Merge excel files into a single excel spreadsheet

In a continuation Excel VBA tutorial series of data manipulation using Macros; Today, we will try to merge excel files in a single excel spreadsheet. The source of the data may be from the same worksheet or from the closed workbook.

We will merge excel files into a single sheet. For example, individual states data are placed on different sheets. What we need to do is we need to make it a master file. For Example, your data look like below.

Raw-Data-Merge-Multiple-excel-file There are almost 51 sheets in my sample workbook. Now if I give you this task to create a master file how long time will it take? Probably it will take almost 1 hour, right? And at the time it will be very tedious to do this as you need to create a new sheet and copy and paste the records in new sheet for one by one.

But at the same time, a small piece of VBA code as in below picture will give you immense benefit. For that, you don’t need to know how to write the VBA code. But you need to know where to place the VBA code and how to run VBA code.

Write-code-for-Merge-Multiple-excel-file

Refer this small excel VBA code video tutorial to copy and run it

How to merge excel files in a single excel spreadsheet step by step:

  1. Press Alt + F11 to go to VBA page
  2. From the Menu choose insert – Module
  3. Copy and paste the below VBA code in the code window.
  4. Press F5 to run the code.

Sub Combine()

Dim J As Integer

On Error Resume Next

Sheets(1).Select

Worksheets.Add

Sheets(1).Name = "Combined"

Sheets(2).Activate

Range("A1").EntireRow.Select

Selection.Copy Destination:=Sheets(1).Range("A1")

For J = 2 To Sheets.Count

Sheets(J).Activate

Range("A1").Select

Selection.CurrentRegion.Select

Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select

Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)

Next

End Sub

Result: New Excel Sheet Opened containing combined date with a name "Combined"

After running the code, you will see a new called “Combined” has been created and all the data from the other sheet is now merged into the combined sheet. And you combine sheet will look like below

See-Combined-sheet-all-data-now-merged

It will take not more than 10 seconds to complete the entire tasks. Isn’t that interesting? That’s why a small piece of code will help you to go back home on time.

In the very next topic, we will cover how to merge excel files from the closed workbook.

Till then please download the Excel macro file from here and play with it.

If you are regularly following our blogs you will notice that we are trying to cover a lot of things to automate the process through VBA. Please follow the below links:

1 Response
  1. krishnaveni

    if we are having same headers, with multiple sheets, then how can we identify, that the header is belonging to particular sheet.
    is there any solution for that?
    “in combine sheet, can we separate sheets with sheet name?”
    is there any possibility?

Leave a Reply

Related Tutorials

Delete Duplicate in Excel or Remove Duplicate in Excel
November 9, 2018
Excel Formulas PDF
September 6, 2018
How To Lock Cells in Excel | Unprotect Excel
August 13, 2018
4x Faster at Excel
August 6, 2018
Separate Content of One Excel Cells into Separate Columns
August 3, 2018
How to Transpose Excel Columns to Rows | Paste Special Method
July 26, 2018
How to create sparklines in Excel
July 19, 2018
AutoSum in Excel with Shortcut
July 17, 2018
OFFSET Function in Excel
July 6, 2018
Strikethrough Shortcut in Excel & Word
July 4, 2018
INDIRECT Function with SUM, MAX, MIN & Independent Cell Value
June 29, 2018
Pivot Table Slicers In Excel
June 12, 2018
How to Split Cells in Excel using Text to Column
June 7, 2018
How to Wrap Text in Excel Automatically and Manually
June 6, 2018
How to Hide/Unhide Column in Excel
June 5, 2018
Highlight row based on cell value
June 4, 2018
Learn how to remove blank cells in Excel
June 3, 2018
How to Group Numbers, Dates & Text in Pivot table in Excel
June 1, 2018
5 Powerful Tricks to Format cells in Excel
May 31, 2018
Insert a Picture into a Cell in Excel
May 25, 2018
What is ISFORMULA Function and FORMULATEXT Function
May 21, 2018
How to Use SUBSTITUTE Function
May 21, 2018
Excel Quartile Function in Excel
May 8, 2018
How to use the Excel PERCENTILE function
May 7, 2018
Insert or Type degree symbol in Excel with Autocorrect Feature
May 7, 2018
25% Discount
No prize
All Courses at $200
Almost!
10% Discount
Free Ebook
No Prize
No luck today
Almost!
50% Discount
No prize
80% Discount
Get a chance to boost your knowledge!
Use this coupon code for any course that you wish for. 
Our in-house rules:
  • You can choose any course & redeem coupon
  • If you find any difficulty, mail us on [email protected]
  • Wheel Spin will end soon
  • Coupon code can be applied within 2 days.