How do I fill-in sheet 1 with data from sheets 2, 3, 4 … ?

Like Samuel L. Jackson in Jurassic Park, this one’s a classic. You and your team are sharing a single Workbook, with each of you operating on your own Sheet. Once everybody is done, you need to combine the data from each Sheet into a single, continuous Sheet for import into a different program. (Or a final pivot table. Or a report to your manager. Or a what-the-flip-ever …)

Let’s dissect a real example. Suppose you have a Workbook like this, with data Sheets that have the same headers (but different info on each). You want to combine this data onto the “Import” sheet, which has the exact same headers too.

Almost there you guys, stay with me! The last challenge within Step 3 – Execution is to add a column identifying which data file a given row came from by writing the Worksheet name into a far-right column. Let’s get to it! Lines 86-89 cover another first loop special case — if this is the first time through, then we need to make sure we add a header name! VBA Combine Multiple Excel Files into One Workbook You need to select the workbooks from which you want the source data – the Source files. You need to select or create the workbook to which you wish to put the data – the Destination file. You need to select the sheets from the Source files that you. Excel VBA combine worksheets columns into one worksheet. Consolidate multiple workbooks into one workbook. Assume that you have a lot of workbooks, each workbook contains multiple worksheets. You may want to copy all worksheets of each workbook into a master workbook. For example, I have a folder called “sample” under C:UsersWYMANDesktop.

To run the macro, press the key F5. Data of both sheets will be copied and pasted in an Excel sheet. This is the way we can collate the data in a sheet from different files of Excel through VBA in Microsoft Excel. Steps to Combine Excel Files using VBA Open the visual basic editor (make sure to activate the developer tab if you have it on the ribbon already on the. After that, locate the current workbook from the project window (control + r) and insert a new module there. You’ll have a code window in the.

All Sheets have the same headers but varying rows

Cool. Here’s the code that gets the job done:

Here’s a link to the code above so you can review it side-by-side with the walk through below. Right-click, “Open in new window”.

Let’s review the code using our 4-step VBA process as a guide:

Step 1 – Setup
Step 2 – Exploration
Step 3 – Execution
Step 4 – Cleanup

Step 1 – Setup takes place from lines 11-13, where we make three assignments:

  • wksDst, the “Import” Worksheet
  • lngDstLastRow, the last-occupied row on the “Import” Worksheet
  • lngLastCol, the last-occupied column on the “Import” Worksheet

We know that all the data Worksheets have the same shape, so lngLastCol is going to be the same value for the duration of the script.

(Wondering about the functions LastOccupiedRowNum and LastOccupiedColNum? They’re in the VBA Toolbelt and are also defined on lines 45-87… You will use these functions constantly in Excel, so get used to defining them in your macros!)

The final setup step occurs on line 16, where we assign the initial Destination — this is where our first paste will start.

Next up is Step 2 – Exploration, which occurs inside the loop from lines 19-25. The For Each wksSrc in ThisWorkbook.Worksheets loop iterates through all Worksheets in this Workbook. (LOVE this syntax… so easy to read and understand!)

Line 22 ensures that the “Import” Worksheet is skipped (since that Worksheet is the destination, NOT a source). This phase ends on line 25, where the last occupied row on the source Worksheet is identified — again, leveraging LastOccupiedRowNum from the VBA Toolbelt.

Bandizip official website. Apps for Drivers. Drivers are code that help Windows and MacOS recognize the physical components of your computer, like a printer, graphics card, or mouse. Work on macOS v10.12+. Add new SIP003 plugin: v2ray-plugin. Upgrade ss-local from v3.2.0 to v3.2.5.; Full support the legacy URI which doesn't follow RFC3986.It means the password here should be plain text, not percent-encoded. Creating zip files on a Mac might seem daunting at first, but you have a few options — and plenty of MacOS and iOS tools — at your disposal. While you may have experience creating a zip file. Zip in macos.

We’re onto Step 3 – Execution! Short and sweet here, from line 28 to 31.

The source Range is assigned on line 29, taking advantage of the last row, lngSrcLastRow, which we figured out on line 25 above, and lngLastCol, which we identified wayyy back up on line 13. Finally, we use the Range.Copy method on line 30 to move the data to the destination Range — smooth!

Lines 34-35 are a quick switch back to Step 2 – Exploration, this time taking place on the destination (“Import”) Worksheet. Since new data has been added (in the Execution step above), we recalculate the last-occupied row, reset the destination range and continue the loop on to the next Worksheet.

That’s it, no Step 4 – Cleanup necessary!

Here’s a 4-minute guide to the code above, with an emphasis on the Exploration and Execution steps:


Combining multiple Sheets into one Sheet with VBA like a boss? If not, let me know and I’ll help you get what you need! And if you’d like more step-by-step, no-bullshit VBA guides delivered direct to your inbox, join my email newsletter below.

Get the VBA Toolbelt!

Quit digging through old projects and forums like a chump! Download the VBA Toolbelt and start with the most common Excel tasks already done for you.

Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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.

by Allen Wyatt
(last updated March 28, 2020)

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.

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.


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 Office 365. You can find a version of this tip for the older menu interface of Excel here: Condensing Multiple Worksheets Into One.

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!

Need to set up a workbook that includes a worksheet for each week of the year? Here's a couple of quick macros that can ..

Discover More

Do you need your macro to select all the visible worksheets (and just the visible ones)? It's not as easy as it sounds, ..

Discover More

Need a quick way to have a worksheet for each day in a month? Here's a macro that makes the worksheet creation a snap.

Merge Multiple Sheets Into One Sheet Vba File

Discover More

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

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
End If
Next s
Alan Elston

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..

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!

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!

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

R Merge All Sheets Into One Table

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?

Edit should be
Dim Cnt As Long

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
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
' 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

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.

Merge All Workbooks Into One Sheet Vba

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

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:…….…. ----- ----- ….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

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


Excel Combine Data From Multiple Sheets

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.