Copy multiple workbooks to one master sheet

boele

New Member
Joined
Jan 16, 2014
Messages
9
Hi guys, I use the following code to try to copy multiple worksheets in one file:
Code:
Option Explicit
 
Sub CombineData()
    Dim oWbk As Workbook
    Dim sFil As String
    Dim sPath As String
     
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
    .AskToUpdateLinks = False
 
         '   On Error GoTo exithandler
        sPath = "C:\Users\kber\Desktop\Kevin\Projecten\Integratie advieslijsten"
        ChDir sPath
        sFil = Dir("*.xls")
        Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through
             
            Set oWbk = Workbooks.Open(sPath & Application.PathSeparator & sFil) 'opens the file
            oWbk.Sheets.Copy
            oWbk.Close False 'close source workbook
            sFil = Dir
             
        Loop ' End of LOOP
         
exithandler:
        .ScreenUpdating = True
        .DisplayAlerts = True
        .EnableEvents = True
    End With
    
 
    
End Sub
The code opens all four workbooks and now is my question how to copy these workbooks to one (master)workbook. Thank you in advance!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
you are using the words workbooks and worksheets and I am confused
does second workbook contain, say 4 worksheets and do you wish to copy these into one sheet of a new empty master workbook
 
Upvote 0
Thank you for your response oldbrewer. What I want to do is to copy all the sheets from the four workbooks in the folder to one file. So for example Workbook 1: 4 sheets Workbook 2: 2 sheets, Workbook 3: 1 sheet and Workbook 4 contains 2 sheets. I want to copy the total of (4+2+1+4) 11 sheets to one masterfile. Thanks!
 
Upvote 0
I suggest you create your master workbook, open it, and turn on record macro. Then open workbook 1, go to sheet 1 edit select all, copy, go back to master and paste, then stop macro. Look at the code and proceed from there. you will need to locate the first empty row in the master before each paste.
 
Upvote 0
I suggest you create your master workbook, open it, and turn on record macro. Then open workbook 1, go to sheet 1 edit select all, copy, go back to master and paste, then stop macro. Look at the code and proceed from there. you will need to locate the first empty row in the master before each paste.
Used some other code and works fine now :)
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,896
Members
449,477
Latest member
panjongshing

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