Copying worksheets from other workbooks

MOORED

New Member
Joined
Sep 25, 2017
Messages
14
Hi All,

i have about 50 workbooks all in the same folder. In each workbook tab 3 is named "commercial"

is there an easy way to extract just this tab/worksheet from each in to another workbook.

Kind regards

DM
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this, changing the folderPath string containing the 50 workbooks. Alternatively, Application.FileDialog(msoFileDialogFolderPicker) could be used, allowing you to browse and select the folder.

Code:
Public Sub Copy_Commercial_Sheet_From_All_Workbooks_In_Folder()

    Dim folderPath As String, fileName As String
    Dim destinationWorkbook As Workbook, sourceWorkbook As Workbook
    
    Set destinationWorkbook = ActiveWorkbook
    
    folderPath = "C:\path\to\folder\"

    folderPath = Trim(folderPath)
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
    
    Application.ScreenUpdating = False
    
    fileName = Dir(folderPath & "*.xlsx")   'NOTE - .xlsx workbooks
    While fileName <> vbNullString
        Set sourceWorkbook = Workbooks.Open(folderPath & fileName)
        With destinationWorkbook
            sourceWorkbook.Worksheets("Commercial").Copy After:=.Worksheets(.Worksheets.Count)
        End With
        sourceWorkbook.Close savechanges:=False
        fileName = Dir
    Wend
    
    Application.ScreenUpdating = True
    
    MsgBox "Done"
    
End Sub
 
Upvote 0
brilliant thanks for you quick response, I will try this afternoon but following what you written looks spot on many thanks

DM
 
Upvote 0

Forum statistics

Threads
1,214,869
Messages
6,122,012
Members
449,060
Latest member
LinusJE

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