Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Merging Many Workbooks.

Merging Many Workbooks

Written by Allen Wyatt (last updated November 25, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

Joy ran into a problem merging quite a few workbooks together. The majority of the workbooks—about 200 of them, all in a single folder—each contain a single worksheet, but some contain more. The worksheets forming each of these workbooks needs to be added to a single workbook.

The easiest way to do merges of this magnitude—particularly if you have to do it often—is with a macro. The following macro displays a dialog box asking you to select the files to merge. (You can select multiple workbooks by holding down the Ctrl key as you click each one.) It loops thru the list you select, opening each one and moving all its worksheets to the end of the workbook with the code.

Sub CombineWorkbooks()
    Dim FilesToOpen
    Dim x As Integer

    On Error GoTo ErrHandler
    Application.ScreenUpdating = False

    FilesToOpen = Application.GetOpenFilename _
      (FileFilter:="Microsoft Excel Files (*.xls?), *.xls?", _
      MultiSelect:=True, Title:="Files to Merge")

    If TypeName(FilesToOpen) = "Boolean" Then
        MsgBox "No Files were selected"
        GoTo ExitHandler
    End If

    x = 1
    While x <= UBound(FilesToOpen)
        Workbooks.Open FileName:=FilesToOpen(x)
        Sheets().Move After:=ThisWorkbook.Sheets _
          (ThisWorkbook.Sheets.Count)
        x = x + 1
    Wend

ExitHandler:
    Application.ScreenUpdating = True
    Exit Sub

ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub

In the process of adding the worksheets to the end of the workbook, Excel will automatically append a (2), (3), etc. when duplicates worksheet names are detected. Any formulas in the book referring to other sheets will also be updated to reflect the new names.

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 (12652) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Merging Many Workbooks.

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

Changing How Word Presents Your Document

Tired of the old black-on-white text displayed by Word? Depending on your program version, you can configure Word to show ...

Discover More

Word 2010 Graphics (Table of Contents)

One way to enhance your documents is with Word's powerful graphics capabilities. Discover how to best utilize graphics ...

Discover More

Creating a String

Need to use a macro to create a text string? One easy way to do it is to use the String function, described in this tip.

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Stopping a Workbook from Persistently Auto-Loading

Excel has the capability to automatically open workbooks when you first start the program. You may not want to have one ...

Discover More

Saving All Open Workbooks

Wouldn't it be nice to have a single command that would save each of your open workbooks, all at once? It's easy to do ...

Discover More

Unresponsive Excel when Double-Clicking a Workbook

There are two ways you can load a workbook in Excel, and each approach should result in the workbook being loaded ...

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 nine minus 5?

2019-10-16 08:37:13

Debbie Sala

I was tasked with creating a workbook to track supervisor and temp supervisor qualifications for each of our 4 maintenance shops. That was an easy process, however, the hard part is trying to figure out how to combine the 4 workbooks with multiple worksheets into one master workbook. I can use the macro to merge the worksheets but then I have one workbook with the same sheets 4 different times and no break in them to show the separate shops. Is there a way to actually create a master workbook that contains for workbooks containing multiple worksheets or do I just need to insert a new "sheet" as a shop name tab?


2018-07-08 10:42:13

Chalina Anderson

Such a time-saver ... thank you for posting this, as my task for the weekend was to consolidate and format 14 files into one ... perfect timing! Because my files were in multiple folders, I copied and pasted them into a single folder, then selected all by highlighting the first file and then hovering over the last in the list and pressing SHIFT while left-clicking the mouse. I then had to answer questions about updating links, which is normal. Great tool! Thanks again!


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.