I have a whole stack of files that I need to copy into a report.
There are two for each Account number. The account numbers are
listed in a worksheet. The files are saved as the account number
then _06 and _07 on the end. I am trying to write a loop to cycle
through the account numbers and copy the files in. But I am getting
a "Run-time Error 9 - Subscript out of range" error.
I'm only new to doing this sort of code and I have no idea what I'm
doing wrong. Would someone let me know?
Sub Test()
i = 3
Sheets("Final Report").Select
Do While Cells(i, 1) <> ""
Workbooks.Open Filename:=Cells(i, 1) & "_06.xls"
Sheets(Cells(i, 1) & "_06.xls").Copy Before:=Workbooks("CHEP
Milk Run Transport " & Format(Now, "yyyy-mm") & ".xls").Sheets(1)
Windows(Cells(i, 1) & "_06.xls").Close
Workbooks.Open Filename:=DocName & "_07.xls"
Sheets(DocName & "_07").Copy Before:=Workbooks("CHEP Milk
Run Transport " & Format(Now, "yyyy-mm") & ".xls").Sheets(1)
Windows(DocName & "_07.xls").Close
i = i + 1
Loop
End Sub