have a question about merging mutiple workbooks

rachelkou

New Member
Joined
Nov 1, 2007
Messages
21
Hello,
I need some help with excel. I have more than twenty workbooks, inside each workbook, the columns are exactly the same with different numbers. I want to merge all workbooks into one worksheet in one workbook . (usually, I just open every workbook, then copy and paste the content into the first workbook)
Anyone knows how to do it?

Thanks so much!!!!!!!!!!!!!!!!!!!!!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
try
Code:
Sub test()
Dim myDir As String, fn As String, flg As Boolean
myDir = "c:\test" '<- change here
fn = Dir(myDir & "\*.xls")
Do While fn <> ""
    If fn <> ThisWorkbook.Name Then
        With Workbooks.Open(myDir & "\" & fn)
            With .Sheets(1).UsedRange
                If flg Then
                    .Resize(.Rows.Count-1,.Columns.Count).Offset(1).Copy
                Else
                    .Copy
                End If
                ThisWorkbook.Sheets(1).Range("a" & Rows.Count).End(xlUp)(2).PasteSpecial
                flg = True
            End With
            .Close False
        End With
    End If
    fn = Dir()
Loop
End Sub
 
Upvote 0
Thank you all very much for help, especially jindon! Your macro works very well and solve my problem. But, why it keeps asking me whether I want to save the large amount of data on the clickboard?
Thanks!!!!!!!!!!!!
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,575
Members
449,318
Latest member
Son Raphon

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