Hey guys,
So I have code written to merge the data from multiple spreadsheets into one. It works fine when I first write the program and press play, I can even press play multiple times and it will append the data to the bottom of the spreadsheet. However, if I save it and close it (with or without hitting play) and try to run the program once I open it I get an error.
VBA Error.jpg
Is there something I did wrong or am missing? Any help would be most appreciated.
Here is a copy of the code that I used.
'Finding files in folder
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
MyFile = Dir("C:\Basic Data Transfer\")
'Making sure file has data
Do While Len(MyFile) > 0
'Ignoring File in folder
If MyFile = "zmaster.xlsm" Then
Exit Sub
End If
'Open the files in the folder
Workbooks.Open (MyFile)
'To copy specific cells from files
Range("A2:A3:D2:D3").Copy
'Close the files
ActiveWorkbook.Close
'Finding first empty row in master spreadsheet
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'Paste the data onto active sheet, on blank cells just determined
ActiveSheet.Paste Destination:=Worksheets("sheet1").Range(Cells(erow, 1), Cells(erow, 4))
'Repeating for the next file
MyFile = Dir
Loop
End Sub
Bookmarks