How to merge multiple excel files
Tutor 5 (73 Reviews)
Excel Tutor
Still stuck with a Excel question
Ask this expertAnswer
To merge multiple Excel files, use one of these reliable methods depending on your needs and platform: Power Query (Get & Transform), VBA macro, or a script (PowerShell or Python). Choose Power Query for ease and repeatable consolidation, use VBA when you need a custom automated workbook-only solution, and use scripting when working with many files or automating outside Excel.
Which method should I choose and why?
-
Power Query — Best for repeatable, GUI-driven merges, preserves table structure, handles different column orders, and performs transformations during import.
-
VBA macro — Best when you must keep everything inside Excel and want a single-click merge inside a workbook.
-
PowerShell or Python (pandas) — Best for large-scale automation, scheduled tasks, or when Excel is not installed on the machine.
-
Copy/Paste — Use only for one-off tiny merges when data size is trivial, and consistency does not matter.
How to merge multiple Excel files using Power Query (recommended)
Windows and Mac differences
-
In Windows Excel, Power Query is under Data > Get Data > From File > From Folder.
-
In Mac Excel, Power Query functionality exists, but the user interface differs: use Data > Get Data > From File > From Folder if your Excel for Mac has Get & Transform; otherwise, use the VBA method or a script. Recent Mac versions include Get & Transform, but menu labels may vary.
Step-by-step (Power Query — folder of files with same structure)
-
Put all the Excel files you want to merge into a single folder.
-
Open a new Excel workbook.
-
On the Data tab choose Get Data > From File > From Folder.
-
Browse to the folder and click OK.
-
In the preview window, click Combine > Combine & Transform Data.
-
In the combine dialog, select the worksheet or table that is common across files, then click OK.
-
Power Query editor opens, showing a sample transformation. Inspect the columns and applied steps.
-
Make transformations as needed (remove columns, change data types, filter rows).
-
When ready, click Close & Load (or Close & Load To… to choose where to put combined data).
-
To refresh and incorporate new files placed in the folder later, right-click the query output table and choose Refresh.
Notes and tips
-
Ensure consistent column names and data formats for the smoothest merge.
-
Use Excel Tables (select data and press Ctrl+T) inside each source workbook to make table detection consistent.
-
When columns differ, Power Query will create nulls for missing columns; handle these via "Remove columns" or "Fill" transformations.
-
Query steps are recorded and repeatable, enabling automated refresh.
How to merge multiple Excel files using a VBA macro
When to use VBA
Use VBA when Power Query is unavailable, when you need a custom in-workbook process, or when you must run the merge from an Excel button or workbook open event.
Step-by-step (VBA)
-
Open a new blank workbook.
-
Press Alt+F11 to open the VBA editor.
-
Insert a new module: Insert > Module.
-
Paste this macro into the module:
Sub MergeAllExcelFilesInFolder()
Dim folderPath As String
Dim filename As String
Dim wbSource As Workbook
Dim wsDest As Worksheet
Dim lastRowDest As Long
Application.ScreenUpdating = False
folderPath = ThisWorkbook.Path & "\MergeFolder\" ' Change path or prompt user
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
filename = Dir(folderPath & "*.xlsx")
Set wsDest = ThisWorkbook.Worksheets(1)
wsDest.Cells.Clear
Do While filename <> ""
Set wbSource = Workbooks.Open(folderPath & filename, ReadOnly:=True)
wbSource.Worksheets(1).UsedRange.Copy
lastRowDest = wsDest.Cells(wsDest.Rows.Count, 1).End(xlUp).Row
If lastRowDest = 1 And Application.WorksheetFunction.CountA(wsDest.Rows(1)) = 0 Then
wsDest.Range("A1").PasteSpecial xlPasteValues
Else
wsDest.Cells(lastRowDest + 1, 1).PasteSpecial xlPasteValues
End If
wbSource.Close SaveChanges:=False
filename = Dir()
Loop
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Merge complete"
End Sub
-
Adjust
folderPathto point to the folder that contains the files to merge or add code to prompt the user. -
Run the macro via Run > Run Sub/UserForm or attach to a button.
VBA tips
-
Test on copies of your files before running production merges.
-
When source files have headers, modify macro to skip header rows after the first file.
-
Use error handling for locked files or unexpected formats.
How to merge using PowerShell (Windows) or Python (cross-platform)
PowerShell (simple CSV/XLSX via Excel COM or export to CSV)
-
For many files, export sheets to CSV first, then use PowerShell to combine CSVs.
-
Example (combine CSVs):
Get-ChildItem -Path "C:\Folder\*.csv" | ForEach-Object {
Import-Csv $_.FullName
} | Export-Csv -Path "C:\Folder\merged.csv" -NoTypeInformation
Open
merged.csvin Excel.
Python (pandas) — recommended for advanced automation
-
Ensure Python and pandas are installed.
-
Example script to combine Excel files where each file has a single sheet or same-named sheet:
import pandas as pd
import glob
files = glob.glob(r"C:\Folder\*.xlsx")
dfs = []
for f in files:
df = pd.read_excel(f, sheet_name=0)
dfs.append(df)
merged = pd.concat(dfs, ignore_index=True)
merged.to_excel(r"C:\Folder\merged.xlsx", index=False)
-
Python approach handles large datasets, allows complex cleaning, and can be scheduled with system task schedulers.
How to handle common issues when merging
-
Mismatched headers — Standardize headers across files before merging or map columns in Power Query.
-
Mixed data types — Explicitly set data types in Power Query or clean types in Python/pandas.
-
Hidden rows/filters — Unhide and clear filters in source files before merging or use transformations to remove unwanted rows.
-
Performance with large files — Use Power Query with sampling, or use Python/pandas for better memory handling.
Where to go from here?
-
Tell me which method you prefer and the file types you have (XLSX, XLS, CSV).
-
Request a tailored VBA macro, Power Query steps with screenshots, or a Python script, and I will provide the exact code and configuration.
Get Online Tutoring or Questions answered by Experts.
You can post a question for a tutor or set up a tutoring session
Answers · 1
How to merge two names in excel
Answers · 1
How to merge first and last name columns in excel
Answers · 1
How to merge first and last name in excel
Answers · 1
How to merge multiple excel files
Answers · 1