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: Condensing Multiple Worksheets Into One.

Condensing Multiple Worksheets Into One

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


15

If you get workbooks that have identically structured data on each worksheet, you may be interested in a way to combine the multiple worksheets into a single, large worksheet.

The concept behind doing the condensation is rather easy: You simply need to copy the data from the second and subsequent worksheets to the first empty row on the first worksheet. Excel does not include a tool that allows you to do this automatically, but it is a great candidate for a macro. Remember, though, that the structure of each worksheet you are condensing should be identical.

The following macro steps through all the worksheets and combines the data to a new worksheet that it adds at the beginning of the workbook.

Sub Combine()
    Dim J As Integer
    Dim s As Worksheet

    On Error Resume Next
    Sheets(1).Select
    Worksheets.Add ' add a sheet in first place
    Sheets(1).Name = "Combined"

    ' copy headings
    Sheets(2).Activate
    Range("A1").EntireRow.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")

    For Each s In ActiveWorkbook.Sheets
        If s.Name <> "Combined" Then
            Application.GoTo Sheets(s.Name).[a1]
            Selection.CurrentRegion.Select
            ' Don't copy the headings
            Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
            Selection.Copy Destination:=Sheets("Combined"). _
              Cells(Rows.Count, 1).End(xlUp)(2)
        End If
    Next
End Sub

When the macro is done, the first sheet in the workbook, named Combined, has all the data from the other worksheets. The other worksheets remain unchanged.

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 (8884) 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: Condensing Multiple Worksheets Into One.

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

Library Not Registered Error

There are lots of error messages that can pop up in Excel from time to time. One of the most confusing may be the ...

Discover More

Frequent Workbook Recovery Prompts

When you open a workbook, Excel examines that workbook to make sure it can understand the data it contains. This can lead ...

Discover More

Making Columns the Same Length

Balancing the length of each column in a multi-column page layout can be a challenge. Here's a quick way to get Word to ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Quickly Copying Worksheets

Excel provides a little-known way to copy worksheets simply by clicking and dragging. Here's how to do it.

Discover More

Changing the Color of Worksheet Gridlines

Want the gridlines in your worksheet to be a different color? You aren't limited to stodgy black; Excel lets you make ...

Discover More

Shortening Worksheet Tabs

When worksheet names are quite long, it can present problems in displaying those names in the tabs at the bottom of the ...

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 seven minus 7?

2024-03-28 06:57:02

jamies

Copying formulas that reference data in another sheet, or is to be moved to different rows or columns can, and often does cause extreme annoyance.
A simple technique
In a read only version, or a temporary copy of the source workbook, or in a copy 'sheetname (2)' of the intended source worksheet
first search for a string such as "£$£%" in the formulas of the range to be moved -
checking it is not in that range.

Then change all "=" to be that string
Now the data will move without Excel altering formulas.

Paste into a temporary worksheet of the target workbook a similar location
formats colours fonts etc.
But you may not want data validation - so clear that after the copy

Now change the "£$£&" back to "=" and you have the formulas copied without Excel adjustments.

If you were wanting to change some external sheet or workbook references it may be better to do that before restoring the "="
so that the replace will be actioned without Excel verification of formulas and references.
So - you can change a folder name, and then change a worksheet name as separate actions.

Next action - move the data to the appropriate location so that Excel adjusts references

Maybe - depending on the needs -
change the "=" back to the string before the move and then back to being a formula after the move.

Final action - move the copied and adjusted range to the place in the sheet where it is actually needed.

Use copy paste special values to check the effect of data in that new range on the system - alignment such as for charts
then paste special formats, and then formulas to set formats and hopefully get the whole set of data as you need it..

Note maybe more than you need in the above - but hopefully all that you need.


2024-03-28 06:40:20

Paul

Another option with Excel 365 is VSTACK.

Again your data must have the same structure on each sheet.

On a new sheet, type =VSTACK(

Then go back to the first sheet and highlight the data to include. On this first sheet, select the headings as well as the data
Type in a comma, go to second sheet and highlight data (this time not including headings)
Repeat the last step for all other sheets, close the brackets and press enter.

Formula is: =VSTACK(first set of data including headings, second set of data, third set of data....)

An advantage of this method is that if you edit the data on one of the original sheets, it will update the data on the stacked sheet.

A drawback is that the stacked data is a spilled range, so there are restrictions on what you can do with it.


2021-02-18 13:42:10

Alan Elston

Hello Amita

You can refer to a worksheet by its tab number , ( also known as its item number or Index).
In Allen Wyatt’s macro, you can see that he is looping all worksheets via this code section

For Each s In ActiveWorkbook.Sheets
'
'
'
'
'
'
Next s

That code section is responsible for looping through all worksheets.
If you were to modify that code section something like the following, then you would only be looping from the 7th tab

For Each s In ActiveWorkbook.Sheets
If s.Index > 6 Then
'
'
'
'
'
'
Else
End If
Next s


Alan Elston


2021-02-17 18:56:20

Amita

Can this be used to only combine sheets after a certain number? For example I have a workbook, where the number of sheets after sheet 6, can vary in number which are the sheets I want to combine. I essentially want to use a greater than sheet 6 function....


2020-11-27 13:18:22

Peyton Brown

This macro worked really well to combine the worksheets. I was trying to copy the data in the combined worksheet into another workbook but I keep getting the message "The information cannot be pasted because the Copy area and the Paste area are not the same size and shape." I have been trying to paste cell values and only have my cursor in a single cell. Any advice?

Thank you very much for the help!


2020-06-29 10:05:47

Kathrin

Thank you very mich for that makro! Very helpful! Could you maybe help me with one question? My heading contains 5 instead of 1 row. How could I adjust that?

Thank you very much in advance!

Best


2020-04-23 05:12:34

Alan Elston

Hi Andrea
It is a bit different what you want.
It is a very common thing to do, what you want. But giving you a full macro here will look a bit messy in the confines and format limitations of a Comment section. It is a complete new macro you need , not just a few changes to Allen Wyatt's above.
A Google search with like “VBA combining multiple workbooks into one” will flood you with examples.

If you then need further help it would probably be best to ask at a help forum, such as excelforum com or mrexcel com
You will get a quick answer there. If you are not in a rush I would do it for you over at excelfox com when I have time

Alan Elston


2020-04-22 19:49:13

Andrea

Hello,
This is exactly what i need except that the source is from different workbooks/files called FC_1, FC_2,FC_3... stored in the same directory.
The sheets is called "Account" for all files and have the same format. please can you help me?
Thanks
Andrea


2020-04-21 05:35:03

Alan Elston

Edit should be
Dim Cnt As Long


2020-04-21 04:49:52

Alan Elston

Hello Tina Glynn
The macro from Allen Wyatt is looping for each worksheet by virtual of these two lines
For Each s In ActiveWorkbook.Sheets
Next

s is Dimensioned ( declared ) as a worksheet

You can do it a bit differently in your case:
_ You can ignore the s
_ In VBA you can reference a worksheet by its Item number, which is its Tab number counting from the left.
_ Allen Wyatt’s macro adds a new worksheet at tab number 1, so then your first 3 tabs will shift to the right by one place and will then have the item numbers of 2 3 and 4

An alternative Looping section for you would be something like:

Dim Cnt
For Cnt = 2 to 4
Application.GoTo Worksheets.Item(Cnt).[a1] ' This will go to the second, third and Forth worksheet, Items 2, 3 and 4
Selection.CurrentRegion.Select
' Don't copy the headings
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy Destination:=Sheets("Combined"). _
Cells(Rows.Count, 1).End(xlUp)(2)
Next Cnt



Alan Elston


2020-04-20 15:16:15

Tina Glynn

Can this be used to only combine 3 worksheets and then stop? I have a workbook with 15 sheets, but I only want this to work for the first 3 sheets.


2020-04-20 12:54:31

Peter

I understood, thank you, gentlemen, for your time!


2020-04-18 05:04:38

Alan Elston

Hi Peter…….The full syntax of what Allen Wyatt is using is like …….Cells(Rows.Count, 1).End(xlUp).Item(2) ……..….Item(2) will give us the cell just below the cell given by…….Cells(Rows.Count, 1).End(xlUp) ………….Cells(Rows.Count, 1).End(xlUp) is the same as …….Cells(Rows.Count, 1).End(xlUp).Item(1) ……………….It is not to easy to explain how the items are assigned for a range……See the demo that I have done for you here:…….…. ----- http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=13070&viewfull=1#post13070 ----- ….As you will see, item numbers are not restricted to the range given. They keep going. …Cells(Rows.Count, 1).End(xlUp) returns just one cell…..But item(2) is the cell beneath…. Item(3) is two cells beneath ….etc…. ……As you will see, Item numbers are not restricted to just the range itself. The item numbers keep going. They go in a sequence of ... all columns in a row, ... then the next row ... etc........... The column count is determined by the original range, but the rows are not limited.…………Alan Elston


2020-04-18 04:49:12

Peter Atherton

Peter
If Cells(Rows.Count, 1).End(xlUp).Row gives the last row number then Cells(Rows.Count, 1).End(xlUp)(2) gives an offset of 1 row. You can test this in some data with the line Cells(Rows.Count, 6).End(xlUp)(2).Select


2020-04-17 16:24:14

Peter

Thank you, I come here ofter for the useful information. Can you please tell what digit "(2)" means in the end of

Selection.Copy Destination:=Sheets("Combined"). _
Cells(Rows.Count, 1).End(xlUp)(2)

I can't figure out..

Thanks,


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.