Append multiple sheet form multiple workbooks into one master file

davidmg1982

Board Regular
Joined
Oct 12, 2015
Messages
64
Hi everyone, I have a folder with more than 100 files with different name of course, but the same amount of 5 spreadsheets with identical names and identical columns (quantity and name), Im looking for a solution to merge all those files into a single one with 5 spreadsheets containing all the information.

I have no doubt there must be a solution already posted, but I cant express this request on a simpler way and the solutions I found are not quite what I need, any help you can give me will be very appreciated.
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Start by opening a new, blank workbook. In this new workbook, create 5 sheets with the names corresponding to those in the source files. In each of those 5 sheets, insert the headers (quantity and name) in row 1. Place this macro in a regular module in the new workbook. Change the folder path (in red) where you files are saved to suit you needs. Save the file as a macro-enabled file. Run the macro.
Rich (BB code):
Sub AppendSheets()
    Application.ScreenUpdating = False
    Dim desWB As Workbook, srcWB As Workbook, ws As Worksheet
    Set desWB = ThisWorkbook
    Const strPath As String = "C:\Test\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        For Each ws In Sheets
            With desWB.Sheets(ws.Name)
                ws.UsedRange.Offset(1).Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1)
            End With
        Next ws
        srcWB.Close False
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Start by opening a new, blank workbook. In this new workbook, create 5 sheets with the names corresponding to those in the source files. In each of those 5 sheets, insert the headers (quantity and name) in row 1. Place this macro in a regular module in the new workbook. Change the folder path (in red) where you files are saved to suit you needs. Save the file as a macro-enabled file. Run the macro.
Rich (BB code):
Sub AppendSheets()
    Application.ScreenUpdating = False
    Dim desWB As Workbook, srcWB As Workbook, ws As Worksheet
    Set desWB = ThisWorkbook
    Const strPath As String = "C:\Test\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        For Each ws In Sheets
            With desWB.Sheets(ws.Name)
                ws.UsedRange.Offset(1).Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1)
            End With
        Next ws
        srcWB.Close False
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
Works fantastic! If I had a plus is possible to add the file name as column a?
 
Upvote 0
Place the headers in each sheet of the new workbook in B1 and C1 then try:
Rich (BB code):
Sub AppendSheets()
    Application.ScreenUpdating = False
    Dim desWB As Workbook, srcWB As Workbook, ws As Worksheet, LastRow As Long
    Set desWB = ThisWorkbook
    Const strPath As String = "C:\Test\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        For Each ws In Sheets
            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            With desWB.Sheets(ws.Name)
                .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(LastRow - 1).Value = srcWB.Name
                ws.UsedRange.Offset(1).Copy .Cells(.Rows.Count, "B").End(xlUp).Offset(1)
            End With
        Next ws
        srcWB.Close False
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Place the headers in each sheet of the new workbook in B1 and C1 then try:
Rich (BB code):
Sub AppendSheets()
    Application.ScreenUpdating = False
    Dim desWB As Workbook, srcWB As Workbook, ws As Worksheet, LastRow As Long
    Set desWB = ThisWorkbook
    Const strPath As String = "C:\Test\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        For Each ws In Sheets
            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            With desWB.Sheets(ws.Name)
                .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(LastRow - 1).Value = srcWB.Name
                ws.UsedRange.Offset(1).Copy .Cells(.Rows.Count, "B").End(xlUp).Offset(1)
            End With
        Next ws
        srcWB.Close False
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
Thanks, its giving me an error for .cells (Compile error: invalid or unqualified reference)
 
Upvote 0
Try:
VBA Code:
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of one of your source sheets.
 
Upvote 0
I tried, but the file is in my work computer and here I can install any add-ins, upload any type of files, and cant export files to my personal computer. How else can I help you?
 
Upvote 0
Try simply copying all the data on one of your source sheets and pasting it here.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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