I need to merge all workbooks in a folder to one file, specifications i'm looking is my folder is dynamic so i need a folder picker for the code. Next thing each workbook in the folder has multiple sheets, i need to consolidate only the sheets with name ("report"). Also the data starts from Range ("A7"). it also contains formulas in the individual sheets, so there should not be formula error after combining.
can somebody help?
Sub GetWorkbook()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Path = ThisWorkbook.Path & "\"
Filename = Dir(Path & "*.xlsx")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
ActiveSheet.AutoFilterMode = False
Sheets("Report").Copy After:=ThisWorkbook.Sheets(1)
Range("1:6").EntireRow.Hidden = True
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.DisplayAlerts = True
Combine
Sheets("Home").Select
MsgBox ("Data Consolidated"), vbInformation
End Sub
Function combine
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Combined" And ws.Name <> "Home" Then
ws.Activate
Dim LastRowW As Long
LastRowW = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
ActiveSheet.Range("A7:P" & LastRowW).Copy
Sheets("Combined").Select
Range("A1048576").End(xlUp).Offset(1, 0).Select
ActiveCell.PasteSpecial (xlPasteValues)
ws.Delete
End If
Next ws
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Function
Here is the code, I have mainly 2 worksheets in the macro workbook (combined and home). The second is a function is to copy the details to the combined sheets and delete the other workbooks. This will work only if all the workbooks are saved in the (this workbook path). How to enable a folder picker to consolidate the files in selected folder.