The code below is the beginning of my macro. I have set the automation script to clear data before import and this macro is set to run after export. I am expecting the macro to find the records returned by my query but it seems to run before the data is exported. This causes an exception since the column and row counts are set to 1. Why would the macro seem to run before the export when it is set to run after?
Dim endRow, endCol As Long
Dim m, r, c, i As Long
Dim rng As Range
Set rng = Sheet1.UsedRange ActiveWindow.FreezePanes = False Cells(1, 1) = "Vendor Performance YTD for " & Year(Now()) Cells(1, 1).Font.Bold = True Cells(1, 1).Font.Size = 15 Range("A4").Select endCol = rng.Columns.Count endRow = rng.Rows.Count m = 1 For i = 3 To endCol Step 2 Cells(3, i) = MonthName(m) Range(Cells(3, i), Cells(3, i + 1)).MergeCells = True Range(Cells(3, i), Cells(3, i + 1)).HorizontalAlignment = xlCenter Range(Cells(3, i), Cells(3, i + 1)).Font.Bold = True Cells(4, i) = "Cost" Cells(4, i).HorizontalAlignment = xlCenter Cells(4, i + 1) = "Qty" Cells(4, i + 1).HorizontalAlignment = xlCenter m = m + 1 Next i