Copying a Single Worksheet from Many Workbooks

Written by Allen Wyatt (last updated March 17, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


4

Victor has a ton of workbooks containing monthly financial information for the past ten years. (One workbook for each month in that decade.) He needs to create a workbook that contains the third worksheet from each of these, so he'll end up with a workbook that contains 120 worksheets. Victor knows he can open each workbook and copy the desired worksheets, one at a time, but that is quite tedious. He wonders if there is a way to easily copy the worksheets to a single, new workbook.

This type of repetitive, tedious task is best addressed by a macro. This example will create a new workbook and then look through all the Excel files in a folder (specified in the sPath variable) to get the third worksheet.

Sub CombineThirdWorksheets()
    Dim sPath As String
    Dim Filename As String
    Dim wb As Workbook
    Dim DestWb As Workbook

    ' Set the folder path (make sure path ends with a backslash)
    sPath = "C:\Path\To\Your\Directory\"

    ' Create a new workbook to store the third worksheets
    Set DestWb = Workbooks.Add

    ' Get the first Excel file in the directory
    Filename = Dir(sPath & "*.xls*")

    ' Loop through all Excel files in the directory
    Do While Filename <> ""
        ' Open the current Excel file
        Set wb = Workbooks.Open(sPath & Filename)

        ' Check if there are at least 3 worksheets
        If wb.WorkSheets.Count >= 3 Then
            wb.WorkSheets(3).Copy After:=DestWb.Sheets(DestWb.Sheets.Count)
        End If

        ' Close the current Excel file without saving changes
        wb.Close SaveChanges:=False

        ' Get the next Excel file in the directory
        Filename = Dir
    Loop

    ' Save the destination workbook
    DestWb.SaveAs Filename:=sPath & _
      "CombinedThirdWorksheets.xlsx", _
      FileFormat:=xlOpenXMLWorkbook
    ' Close the destination workbook
    DestWb.Close

    MsgBox "All third worksheets have been combined."
End Sub

To use the macro, make sure all the workbooks you want to process are in a single folder. Then, change the sPath variable within the macro so that it is the full path to the folder. When you run the macro, it will create a workbook, copy all the "third worksheets" into the workbook, and then save the workbook using the name CombinedThirdWorksheets.xlsx.

You could also take a different approach in your macro, relying upon a scripting approach, as shown here:

Sub MergeSheetThree()
    Dim wbSource As Workbook
    Dim wbDest As Workbook
    Dim wsSource As Worksheet
    Dim fso As Object
    Dim folder As Object
    Dim file As Object
    Dim sPath As String
    Dim fileName As String

    ' Set the folder path (make sure path does NOT end with a backslash)
    sPath = "C:\Your\Folder\Path\Here"

    Set wbDest = Workbooks.Add
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder(sPath)

    For Each file In folder.Files
        fileName = file.Name

        If Right(fileName, 5) = ".xlsx" Then
           Set wbSource = Workbooks.Open(sPath & "\" & fileName)
           If wbSource.WorkSheets.Count >= 3 Then
               Set wsSource = wbSource.WorkSheets(3)
               wsSource.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)
           End If
           wbSource.Close False
        End If
    Next

    ' Save the destination workbook
    wbDest.SaveAs Filename:=sPath & "\" & _
      "CombinedThirdWorksheets.xlsx", _
      FileFormat:=xlOpenXMLWorkbook
    ' Close the destination workbook
    wbDest.Close

    Set wbSource = Nothing
    Set wbDest = Nothing
    Set wsSource = Nothing
    Set fso = Nothing
    MsgBox "Merging completed"
End Sub

As with the previous macro, copy all of your workbooks into a single folder and then set the sPath variable to the folder's path. Unlike the previous macro, though, the path should not end with a backslash. In addition, this second macro will only process workbooks that use the XLSX extension, whereas the first one will process any type of workbook (XLS, XLSX, XLSM, and XLSB).

There is one thing that needs to be stressed with either of the macro approaches discussed in this tip—they explicitly fulfill what Victor expressed by simply copying worksheets from one workbook into another. If the worksheet being copied includes formulas that references other worksheets in the source workbook, then those formulas will not work correctly in the copy of the worksheet placed in the target workbook.

Finally, you should note that both macros copy the third worksheet in the Worksheets collection. This may not give you the exact results you expect. For instance, the default names for worksheets added to a workbook are Sheet1, Sheet2, Sheet3, etc. Over time, the worksheets may be moved around, so that Sheet3 is actually the fifth worksheet listed in the worksheet tabs. If you really want Sheet3 to be copied, thinking it is always considered the third worksheet, then you may not get what you expect—a differently named worksheet could occupy the third index position in the Worksheets collection. In such cases, you may be better served to replace Worksheets(3) in either macro with Worksheets("Name of Worksheet") to get the exact one you want. This assumes, of course, that the worksheet you want copied from each workbook uses the same name. You can find more information about worksheet names and worksheet indexes (in the Worksheets collection) at either of these tips:

https://tips.net/T12414
https://tips.net/T11103

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9774) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Searching for Formatting

When searching for text, Word can pay attention to more than just the characters in the text. It can also pay attention ...

Discover More

Adding an Equation Editor Tool

If you use the Equation Editor a lot in creating your documents, you'll benefit by making sure it is accessible as ...

Discover More

Creating Selections

Want a really easy way to create a selection of a group of cells? Discover how to use the Extend key to make this task ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Needing to Save a Workbook Twice

If you save a workbook and then immediately close the workbook, Excel may ask you to save again. This tip looks at ...

Discover More

Closing a Read-Only Workbook

When you create a workbook that is read-only, users can still make changes to the workbook. When they exit, they are ...

Discover More

Viewing Workbook Statistics

Excel keeps track of a range of stats about each workbook you use. If you want to take a look at those stats, it's easy; ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 1?

2025-07-27 11:05:35

J. Woolley

@Dan
I'm not sure what you want to do, but here's how to copy a range from a worksheet named 'MySheet' in the wb workbook to a new worksheet in the DestWb workbook using xlPasteValues.
Replace the following statements in the Tip's CombineThirdWorksheets macro
        ' Check if there are at least 3 worksheets
        If wb.Worksheets.Count >= 3 Then
            wb.Worksheets(3).Copy After:=DestWb.Sheets(DestWb.Sheets.Count)
        End If
with these statements
        Dim ws As Worksheet
        With DestWb
            Set ws = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
        End With
        wb.Worksheets("MySheet").Range("A1:FA200").Copy
        ws.Range("A1").PasteSpecial xlPasteValues
To learn more about macros, our host Allen Wyatt offers the following:
https://store.tips.net/T010157_ExcelTips_The_Macros.html https://usingoffice.com/


2025-07-25 12:03:26

Dan

Thanks for this. Can I ask about changing part of it, please? If instead of copying the third worksheet I wanted to copy a worksheet with a standardised name, and break the links (probably by paste valuing the data), how would I do that?

So far I have changed your code:
If wb.WorkSheets.Count >= 3 Then
wb.WorkSheets(3).Copy After:=DestWb.Sheets(DestWb.Sheets.Count)

To:
ws.CashflowCQC.Range("A1:FA200").Copy After:=DestWb.Sheets(DestWb.Sheets.Count).Range("A1:FA200")PasteSpecial Paste:=xlPasteValues

It is not working. Apologies, I have a lot to learn here.
Thanks,
Dan


2025-03-20 13:23:34

J. Woolley

Re. my previous comment below, here is a better version of the replacement statement:
If LCase(Mid(Filename, InStrRev(Filename, "."), 4)) = ".xls" Then
This version catches an old workbook of type XLS, but the previous version did not. Mea culpa.


2025-03-17 12:47:15

J. Woolley

The Tips says, "...this second macro will only process workbooks that use the XLSX extension, whereas the first one will process any type of workbook (XLS, XLSX, XLSM, and XLSB)." That restriction can be eliminated if this statement in the second macro
        If Right(fileName, 5) = ".xlsx" Then
is replaced by this statement
        If LCase(Left(Right(Filename, 5), 4)) = ".xls" Then


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.