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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
Thanks, this did what I needed it to and helped me with some additional code that I was stuck on.
 
Upvote 0

Forum statistics

Threads
1,215,113
Messages
6,123,165
Members
449,099
Latest member
afishi0nado

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