Link to home
Start Free TrialLog in
Avatar of Nirvana
NirvanaFlag for India

asked on

consolidate from multiple folders

I want to Consolidate multiple workbooks into one the below code work perfectly fine, however it picks only from one folder, however I want this to be picked from subfolders

Sub MergerNP()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
 
'change folder path
Set dirObj = mergeObj.Getfolder("D:\main folder\folder\")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
bookList.Worksheets("7777").Activate

 
Range("A12:VII" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate

 
'Do not change below column
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you need to do  recursive search for files in folder and subfolders
see this Search Files Recursively
SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nirvana

ASKER

Thanks a lot Bill. Just can't understand how few brains are Brilliant and one dumb like me.
Avatar of Bill Prew
Bill Prew

Welcome, glad that was helpful.

~bp