Need to loop through multiple folders (3 folders in same directory) and merge all files from these multiple folders.
The below code consolidates all files from a single folder (A). I need to consolidate all files from 3 different folders: A,B and C.
My question is: how do I add a loop to consolidate files from the remaining 2 folders
This is the excel-vba code:
Sub Merge()
With Worksheets("Sheet2")
Dim bookList As Workbook
Dim MergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Dim sCURFolderPath As String
Dim sHostFolder As String
Application.ScreenUpdating = False
Set MergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
sCURFolderPath = Application.ActiveWorkbook.Path ' Current directory folder
sHostFolder = sCURFolderPath & "\First Month"
Set dirObj = MergeObj.GetFolder(sHostFolder)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
Range("A2:Z" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets("Sheet2").Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End With
End Sub
From Folder. - teylyn