Hi, I'm fairly new to vba so any help is appreciated!
I have a macro that loops through 5 cells B20-B24, opens the files specified in cells, copies the data and stacks them in the main workbook.
What I would like to include is if one on of the files in B20-B24 doesn't exist, for the code to go to the next iteration.
I've tried including a On Error Resume Next before and after the workbooks.open bit but that doesn't seem to work
Code below:
I have a macro that loops through 5 cells B20-B24, opens the files specified in cells, copies the data and stacks them in the main workbook.
What I would like to include is if one on of the files in B20-B24 doesn't exist, for the code to go to the next iteration.
I've tried including a On Error Resume Next before and after the workbooks.open bit but that doesn't seem to work
Code below:
Code:
Sub Copy_Cash()
Application.ScreenUpdating = False
Dim template As Workbook
Dim macro As Worksheet
Set template = ActiveWorkbook
Set macro = template.ActiveSheet
For i = 20 To 24
Workbooks.Open macro.Range("B" & i).Value
Range("A2:P2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks("Template.xlsb").Worksheets("Cash Files").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
ActiveWorkbook.Close SaveChanges:=False
Next i
End Sub
Last edited by a moderator: