I'm trying to figure out why this code works every other time I run it in Access.
I have a spreadsheet that is being built via access query and then exported to Excel. Then I am running this to do a little formatting/cleanup. (It's suppose to select the cell in row 1 copy those values to the last column (in row 1) and then paste them in a specified cell.
It runs perfectly on the first run but I get a debug error if I run the same thing again.
Debug comes up on this line:
.Range(ActiveCell, ActiveCell.END(xlUp).END(xlToRight)).Copy
.
The exact error is "Object Variable or With block variable not set"
Any help would be greatly appreciated. THANKS!
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Dim rng as Range
With myWorkbook.Worksheets("qryAutoBuildFile")
myWorkbook.Sheets("qryAutoBuildFile").Activate
Set rng = Range("A1:CU1").Find("Article").Offset(0, 1)
rng.Select
.Range(rng, rng.END(xlUp).END(xlToRight)).Copy
.Range("A1:CU1").Find("Expr1008").PasteSpecial xlPasteValues
.Range("A1").Select
End With
appExcel.CutCopyMode = False