Hello,
I am seeking help on a some VBA I wrote to copy selected range, within selected sheet for all workbooks within a file folder.
Here is what I want to do:
have the zmaster run a macro to bring in all date from the sheets labeled "Reach". I want columns A-V and then all the way down to the last row of data for each. The amount of data will change very month, so that is why I need to to the last row of data. Then paste all those results from the 3 active workbooks (FS Measures Jan 23, FS Measures Feb 23, FS Measures Mar 23) in the Master starting at A1 on "Sheet1". Here is the code I have so far. However, I get a return error 1004. I would like to be able to rename the workbooks being copied anything I want at any given time. I am not sure why the code is not reading the file names. Workbook is attached.
Sub LoopThroughDirectory()
Dim myfile As String
Dim erow ' last row
myfile = Dir("C:\suppliers-master\") 'location of file
Do While Len(myfile) > 0
If myfile = "zmaster.xlsm" Then
Exit Sub
End If
Workbooks.Open (myfile)
Worksheets("Reach").Activate
Range("A1:V1").End(xlDown).Copy
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 22))
myfile = Dir
Loop
End Sub
Rtn error.PNG
file path.PNG
Bookmarks