Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub loopthroughdirectory()
- Dim myFile As String
- Dim myPath As String
- Dim myExtension As String
- Dim myMainFile As String
- Dim mainFileFinalRow As Integer
- Dim fileToCopyFinalRow As Integer
- ' Insert the path to the folder in which you have all the excel files
- myPath = "C:\Users\Hendro\Desktop\test\folder_to_loop\"
- myExtension = "*.xls*"
- myFile = Dir(myPath & myExtension)
- Do While Len(myFile) > 0
- Workbooks.Open (myPath & myFile)
- fileToCopyFinalRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
- Range(Cells(2, 1), Cells(fileToCopyFinalRow, 11)).Copy
- ActiveWorkbook.Close
- mainFileFinalRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
- ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(mainFileFinalRow, 1), Cells(mainFileFinalRow + fileToCopyFinalRow - 2, 11))
- myFile = Dir
- Loop
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement