Excel VBA CodeTutorials

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.

Excel VBA Macros for Non-Coders

Do you find VBA Macros scary? Did you miss any job opportunity because of it? Get started today with our eBook guide on using – Excel VBA Macros. 140 pages of rich visuals. Download now.

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

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

Excel VBA Macros for Non-Coders

Do you find VBA Macros scary? Did you miss any job opportunity because of it? Get started today with our eBook guide on using – Excel VBA Macros. 140 pages of rich visuals. Download now.

Related posts
AlteryxTutorials

Alteryx Hotkeys - Alteryx Keyboard Shortcuts

2 Mins read
Top 50+ Alteryx Shortcuts for Windows. Alteryx is popularly known as a Self-Service Analytics tool. Business users can build their data workflows…
AlteryxTutorials

Step By Step Guide to Learn Alteryx

6 Mins read
Alteryx Learning Path: The growth in technology has resulted in growth in understanding. In today’s world, humans – fellow businessmen know the…
Excel VBA CodeTutorials

VBA Code to Clean the Date Format

1 Mins read
When it is useful? Most of the time the most annoying problem is when the data is taken from ERP or other…

2 Comments

Comments are closed.