ExcelTutorials

Merge excel files into a single excel spreadsheet

2 Mins read

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, an individual state’s 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 a new sheet for one by one.

But at the same time, a small piece of VBA code as in the 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:

To merge Excel Files in Single Excel Spreadsheet, you have to follow below steps,

  • Step 1: Press Alt + F11 to go to VBA page
  • Step 2: From the Menu choose insert – Module
  • Step 3: Copy and paste the below VBA code in the code window.
  • Step 4: Press F5 to run the code.
[gdlr_core_code style="dark" ]
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
[/gdlr_core_code]

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

After running the code, you will see a new called “Combined” that 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 task. 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.

Related posts
ExcelExcel VBA Code

VBA Code to Split table by Columns

3 Mins read
Step 1: Press the Shortcut keys Alt + F11 to open the Visual Basic for Application window. Step 2: In the Visual…
ExcelExcel VBA Code

Create A Table Of Contents By VBA Code

1 Mins read
Step 1: Press the Shortcut keys Alt + F11 to open the Visual Basic for Application window. Step 2: In the Visual…
ExcelExcel VBA Code

Save Each Worksheet as a Separate PDF

1 Mins read
Step 1: Press the Shortcut keys Alt + F11 to open the Visual Basic for Application window. Step 2: In the Visual…

3 Comments

Comments are closed.