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 erow As Integer
- ' Insert the name of your main file name
- myMainFile = "Combine.xlsm"
- ' 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
- If myFile = myMainFile Then
- Exit Sub
- End If
- Workbooks.Open (myPath & myFile)
- ' This only copies 1 row of data!
- Range("A2:K2").Copy
- ActiveWorkbook.Close
- erow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
- ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 11))
- myFile = Dir
- Loop
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement