Combine Multiple Excel Sheets Into One Sheet Vba

  1. Excel Combine Multiple Spreadsheets Into One
  2. Merge Multiple Excel Files Into One Worksheet Vba
  3. Combine Multiple Excel Sheets Into One Sheet Vba Calculator

Sometimes we want to merge multiple sheets into one sheet so that we can easily analyse the data and turn it into some useful information. This articles will tell you how to merge multiple worksheets into one worksheet using VBA.
Here I have fetched some data from server that returns data into different worksheets. I have added one more sheet and named it as “Master”. Other sheet names doesn’t matter.
Now run this macro.

How to merge sheets using this VBA Macro?

Excel Combine Multiple Spreadsheets Into One

  1. Insert a new sheet and name it “Master” in the workbook. Rename it later if you want.
  2. Insert a module in VBA editor and copy above VBA code.
  3. Run the macro.
  4. You will be asked to select headings. Select the heading and hit OK.

And it is done. All the sheets are merged in master.
How it works?
I assume that you know the basics of object and variable creation in VBA. in the first part we have created object and variables that we will need in our operations.

Tutorial: more Excel VBA tutorials here:

You need to open all files to be able to combine them into one. Instead of doing it manually, select all the files and press the enter key on your keyboard. To select multiple files that are non-adjacent, hold the Ctrl key and clicks the files one by one. For adjacent files, hold the Shift key and click on the last file to select them all. VBA to compile and collate Multiple excel workbooks and sheets data in one sheet in new excel file. Question: Hi I’m looking for comment for below scenario. I have 3 excel file named ABC1, ABC2 and ABC3. I want to copy selected range of rows and column (it’s same for all the 3 excel sheet), in to new excel file. VBA Express: Excel - Combine All Worksheets into One Sub CopyFromWorksheets Dim wrk As Workbook Dim sht As Worksheet Dim trg As Worksheet Dim rng As Range Dim colCount As Integer Set wrk = ActiveWorkbook For Each sht In wrk.Worksheets If sht.Name = 'Master' Then MsgBox 'There is a worksheet called as 'Master'.'

Well most of the things I have explained using comments in vba code. Let’s look at the main part of this vba code.

In earlier articles we learned how to loop through sheets and how to get last row and column using vba.

Here we are looping through each sheet in main workbook using for loop.
For Each ws In wb.Worksheets

Then we exclude “master” sheet from looping, since we will be consolidating our data in that sheet.

Then we get last row and last column number.


Now next line is very important. We have done multiple operations into one line.
Range(Cells(startRow, startCol), Cells(lastRow, lastCol)).Copy _
mtr.Range('A' & mtr.Cells(Rows.Count, 1).End(xlUp).Row + 1)

Merge Multiple Excel Files Into One Worksheet Vba

First we form a range using startRow, startCol and lastRow and lastCol.

This loops runs for all the sheets and copies each sheets data into master sheet.

Finally, in the end of the macro we activate the mastersheet to see the output.

So yeah guys, this is how you can merge every sheet in a workbook. Let me know if you have any query regarding this VBA code or any excel topic in the comments section below.
Download file:

Related Articles:


Combine Multiple Excel Sheets Into One Sheet Vba Calculator

How to loop through sheets

how to get last row and column using vba

Popular Articles: