consolidate tabs from multiple workbooks into one new workbook

utensil

New Member
Joined
Aug 2, 2010
Messages
20
I have a folder with approximately 20 files in it. Each file contains a different amount of tabs. Looking for a way to open each file and then grab all the tabs and consolidate into one 'master' file.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
If the file path is the same for all the workbooks as the file which will host the code then this will work.
Code:
Sub t()
Dim wb As Workbook, sh As Worksheet, fName As String, fPath As String, t As Double
fPath = ThisWorkbook.Path 'If files are in a different folder substitute that path fot 'ThisWorkbook.Path
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
fName = Dir(fPath & "*.xl*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(fPath & fName)
            For Each sh In wb.Sheets
                sh.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
                'Add a delay in case sheets contain voluminous data
                t = Timer + 0.2
                Do While Timer < t
                    DoEvents
                Loop
            Next
            wb.Close False
        End If
        fName = Dir
    Loop
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top