merge multiple files and all sheets

nldstorm

New Member
Joined
Sep 20, 2009
Messages
15
Need your help!

Do you know what the macro would be if I want to merge different sheets (having the same amount of rows but columns may be different) for all open files? With other words, I will have 5 files open, some with 5 sheets and some with one sheet and would like to have all columns out of these 5 files returned into one master sheet.

Thanks!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
For each opened workbook, except the active workbook, the data from each sheet will be copied to the active sheet...

Code:
Option Explicit

Sub test()

    Dim wkbDest As Workbook, wkb As Workbook
    Dim wksDest As Worksheet, wks As Worksheet
    
    Application.ScreenUpdating = False

    Set wkbDest = Application.ThisWorkbook
    Set wksDest = wkbDest.ActiveSheet
    
    For Each wkb In Workbooks
        If wkb.Name <> wkbDest.Name Then
            For Each wks In wkb.Worksheets
                wks.UsedRange.Copy Destination:=wksDest.Cells(wksDest.Rows.Count, 1).End(xlUp)(2)
            Next wks
        End If
    Next wkb
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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