Hi and thanks for all your help thus far.
This code came largely from you guys and it seemed to pass every test that I could think of, however when put to the ultimate test (that being trying to run it with my actual information) if fails and puts things in the wrong order.
I can post a workbook if needed (it will take some work to pull the sensitive info out again) but I hoped that perhaps someone could tell me what might make the code fail only when I start adding real information.
Sub GetSalesData()
Application.ScreenUpdating = False
' Clear previous data in event sheets
For Each WrkSheet In ActiveWorkbook.Worksheets
With WrkSheet
If Not IsError(.Cells(FirstRow, 1).Value) Then
If .Cells(FirstRow, 1).Value = "Ticket" And .Cells(FirstRow + 1, 1).Value <> "" Then
.Rows(FirstRow + 1 & ":" & .Cells.SpecialCells(xlCellTypeLastCell).Row).ClearContents
End If
End If
End With
Next
' Get the number of events
EventCount = Application.WorksheetFunction.CountA(Range("Events").Columns(1))
' Move the Sales data to the event sheets
Sheets("Sales").Select
SalesRow = 2
EventCode = Cells(SalesRow, 1).Value
Do Until Cells(SalesRow, 2).Value = ""
If Cells(SalesRow, 13).Value <> "" Then ' Has a day in column M
If Cells(SalesRow, 1).Value <> "" And Cells(SalesRow, 1).Value <> EventCode Then
EventCode = Cells(SalesRow, 1).Value
End If
If EventCode = "ALL" Then
For i = 1 To EventCount
Call CopyData(Range("Events").Cells(i, 1).Value & " " & Cells(SalesRow, 13).Value)
Next
Else
Call CopyData(EventCode & " " & Cells(SalesRow, 13).Value)
End If
End If
SalesRow = SalesRow + 1
Loop
Call FindChangesCancellations
End Sub
Sub CopyData(DaySheet As String)
With Worksheets(DaySheet)
If .Cells(FirstRow + 1, 1).Value = "" Then
DayRow = FirstRow + 1
Else
DayRow = .Cells(FirstRow, 1).End(xlDown).Row + 1
End If
.Cells(DayRow, 1).Value = Cells(SalesRow, 2).Value ' Number
.Cells(DayRow, 2).Value = Cells(SalesRow, 3).Value ' Type
.Cells(DayRow, 3).Value = Cells(SalesRow, 4).Value & ", " & Cells(SalesRow, 5).Value ' Name
.Cells(DayRow, 5).Value = Cells(SalesRow, 21).Value ' Notes
.Cells(DayRow, 6).Value = Cells(SalesRow, 20).Value ' Table
.Cells(DayRow, 7).Value = Cells(SalesRow, 19).Value ' Specialty
End With
End Sub
Thanks,
Tom
Bookmarks