Excel Automation13 min read

Combining Multiple Excel Files Into One: Copy, Power Query, and What Breaks

Twelve monthly files into one annual register should take a minute. It takes an afternoon because one file has a header in row three and another has a total row at the bottom. Do it once, properly, and it stops being an afternoon.

Short answer

To combine multiple Excel files into one sheet, use Power Query with a From Folder source: point it at the folder, promote the headers once, set the column types and remove any total rows, and it reads every file into a single table. Add a column carrying the source file name before anything else, and verify the result by comparing the row count and a control total against the sum of the individual files. For a handful of files and a one-off need, plain copy and paste is faster.

Which method, for which situation

SituationMethodWhy
Three files, onceCopy and pasteSetting up a query takes longer than the task
Twelve files, every monthPower Query, From FolderSet up once; each month is a refresh
Files from several people, layouts nearly but not exactly the samePower Query, with the cleaning defined in the queryThe differences become query steps rather than manual corrections
Hundreds of filesPower Query, From FolderManual methods are not viable at this volume
Files that change layout unpredictablyNeither — fix the source firstAny method you choose becomes maintenance you cannot control

Method 1: copy and paste, done properly

For a small number of files this is genuinely the right answer. A few habits make it much less error-prone.

1

Add a source column first

Before pasting anything, add a column at the left called Source and fill it with the file name or period as you paste each block. Doing it afterwards means going back through the sheet guessing where one file ended and the next began.
2

Paste values, not formatting

Paste Special → Values. Copying formats from twelve files gives you twelve different date formats, four fonts and a conditional formatting rule that fires unpredictably.
3

Check the header of every file before pasting

If one file has a title row above the header, its columns will be offset by one for its entire block, and nothing in the sheet will tell you.
4

Delete total rows as you go

A subtotal row pasted into the combined data doubles a figure in every total you produce afterwards. It is the most damaging single mistake in a manual combine, and it is invisible.
5

Reconcile when you finish

Count the rows per file and add them up. Compare with the row count of the combined sheet. Then do the same with a numeric total.

The subtotal row is the classic silent failure

Twelve monthly registers, each with a total row. Paste all twelve and you have carried twelve total rows into the annual register. Every pivot table, every SUMIF and every report built on that register is now wrong, and the error is proportional to how many months you included — so it looks plausible.

Method 2: Power Query, From Folder

This is the method worth building. The exact menu labels differ slightly between Excel versions, but the shape of the process is the same.

1

Put the files in a folder of their own

One folder, nothing else in it. A template file, a backup copy or a file open in another window sitting in the same folder will be picked up as data. Subfolders are ignored by default, which is usually what you want.
2

Start from the workbook you want the result in

Data → Get Data → From File → From Folder, then point at the folder. You get a list of the files with their names, dates and paths.
3

Choose Combine, then select the sheet

Excel offers to combine the files and asks which sheet or table to use. It generates a workbook query, a sample file query and a transform function — three separate queries where the actual transformations live.
4

Do the cleaning in the transform query, not in each file

This is the step people miss. Promote the header row, remove the total rows, change the column types and remove unwanted columns inside the transform query. Whatever you do there is applied to every file, including ones added later.
5

Add the source file column

From the folder query, expand the file name alongside the content. Without it, the combined table cannot tell you which file a row came from.
6

Load the result, then check the counts

Load to a worksheet as a table. Compare the row count against the sum of the individual files before you start relying on it.

Where the transformations actually live

Power Query generates this pattern as three queries: a sample file query that defines the shape from one example, a transform file function that applies those steps to every file, and the from folder query that reads the folder and invokes the function. When a file does not combine correctly, the fix almost always belongs in the transform function — and changing it there fixes all the files at once, not just the one that exposed the problem.

When the files are not quite identical

DifferenceWhere to handle it
A title row above the header in some filesRemove the top rows in the transform query, then promote headers — this works if the offset is the same in every file
A total row at the bottomFilter it out in the transform query. If the total row is identifiable by a word in one column, filter on that word
An extra column in one fileRemove or keep the column explicitly in the transform query so every file ends with the same columns
A renamed sheet in one fileStandardise the name in the source files; selecting by position works until somebody inserts a sheet
Files in more than one folderA second From Folder query per folder, then append the results
A file saved as .xls rather than .xlsxConvert it once; older formats are handled less predictably

Method 3: a VBA loop

A macro that opens each file in a folder and appends its rows is a common approach, and a reasonable one if you are already comfortable writing VBA. It is faster than manual pasting and slower than a query to set up.

  • The folder path is hard-coded. Move the folder and the macro stops — if you are lucky.
  • Sheet names are hard-coded. One file with a different sheet name breaks it or, worse, appends the wrong sheet.
  • It does not verify what it did. A macro that appends and reports no error is not evidence that the rows are correct. There is no built-in check unless you write one.
  • Application.ScreenUpdating and DisplayAlerts. Turning these off makes the macro faster and removes the visual clues when it goes wrong. If you do it, build in a log.

The general problem with recorded macros — that they contain positions rather than intentions — is covered in why Excel macros break.

Worked example: twelve monthly registers into one annual register

A business keeps each month's GST sales register in its own workbook, named for the month. Twelve files, all with the same columns, all with a total row at the bottom.

StepWhat happensWhat it avoids
Point the query at the folderTwelve files listed with their names and modification datesManually opening each file to check it is there
Promote headers in the transform queryOne header row used for every fileThe offset errors that come from pasting blocks of different shapes
Filter out the total rowsThe row where the first column contains “Total” is removedTwelve subtotal rows silently doubling every annual figure
Set column types explicitlyDate columns become dates, amount columns become numbersText-formatted amounts that will not sum
Add the source file nameEach row carries the month it came fromHaving to search the files to trace a row
Check the countsSum of the twelve file row counts equals the combined row countA combine that quietly dropped a file

The five things that break a combine

  • Extra rows above the header. A report title in row one shifts the entire file. The query reads the title as the header and the headers as data.
  • Total rows below the data. Read as data, and included in every total you produce.
  • Columns that exist in some files only. Power Query handles this more gracefully than copy and paste, but the resulting column will contain nulls that you need to handle explicitly.
  • Duplicate file names or copies. A file named “August (2).xlsx” is read as a thirteenth month, and nothing flags it.
  • Files that are not data. A template, an instructions file, a workbook that happens to be saved in the same folder. All are read. Keep the folder clean or filter the query by file name.

Verifying the result

CheckHowWhat a failure means
Row countSum the row counts of the source files, compare with the combined tableA file was missed, or a total row was included, or rows were dropped
Control totalSum a numeric column in each source file, compare with the sum in the combined tableValues were converted incorrectly, or rows are missing
Distinct source valuesCount the distinct values in the source columnA file was read twice, or two files carry the same recorded source name
Spot checkPick three rows from the combined table and find them in their source fileThe columns are misaligned — the most serious failure, and the one the totals will not catch

The spot check catches what the totals cannot

If the columns are misaligned, the row count is right and the totals may still be right, because the wrong values were placed in the wrong columns consistently. Picking three rows and confirming them against the source is the only check that catches this, and it takes two minutes.

Common mistakes

  • Combining before checking the files. Open two or three and look at the structure first. It is faster to fix six files than to debug a query that assumed all twelve were identical.
  • Doing the cleaning after the combine. Where a defect belongs to a source file, clean it in the transform query so it stays fixed next month.
  • Leaving the source column out. Then nothing in the output can be traced.
  • Not checking the row count. A combine that loses a file looks entirely normal.
  • Loading to a pivot table. Load the combined data to a table first, then pivot from it. Pivoting directly from a query gives you less room to check before you summarise.
  • Assuming the folder is stable. Somebody will save a copy into it. Either filter the query by file name pattern, or accept that you have to check.

After the combine, the comparison

A combined register is usually the input to something else — a reconciliation against a system report, or a check against last year. That second step is a comparison, and it has the same requirements: a key column, rules stated explicitly, and a check that the counts tie.

The methods for that are in comparing two Excel files. If the comparison is the repetitive part and the combining is already solved, the Piloteq Automate workflow is where the matching rules live as a saved set rather than as formulas in the combined sheet.

If you would rather not build this by hand

Compare the combined file against the source

Once the files are combined, the next question is usually whether the combined register agrees with another set of records. Piloteq Automate applies that comparison on the key columns you choose and returns the missing and changed records with a reason.

  • ✓Rules applied identically across the combined data
  • ✓Missing records reported for each side
  • ✓Duplicate detection across the whole set
  • ✓Results as an exportable difference list
₹1,499 · Single PC License · 12-month license

See how Piloteq Automate fits into a workflow →

Frequently asked questions

What is the fastest way to combine multiple Excel files into one sheet?+

Power Query with a From Folder source. You point it at the folder, define the transformations once — promote the headers, set the column types, remove the total rows — and it reads every file in that folder into a single table. Files added to the folder later are picked up on Refresh, so the work is done once rather than repeated every period.

How do I combine files that have different sheet names?+

In Power Query, the combine step relies on the files having the same structure, so a sheet renamed in one file will not be found. The workable approaches are to standardise the sheet name across the files, or to change the navigation step so it selects a sheet by position rather than by name. Selecting by position works until somebody inserts a sheet ahead of it, so standardising the name is the more durable fix.

Why do I need a source column when combining files?+

Because without it, a row in the combined table has no record of where it came from. When a total does not agree, or a duplicate appears, the first question is always which file it was in — and if you did not keep that, you have to go back to the files and search. Add a column carrying the file name or the period before anything else.

Can I combine Excel files with a macro?+

Yes, and a recorded macro is a reasonable way to learn how. The limitation is that a macro contains hard-coded references — folder paths, sheet names, cell addresses — so it breaks when any of those change, and it often fails silently rather than stopping. Power Query does the same job and adapts to a changed number of files without any code.

What breaks a folder combine in Power Query?+

Five things, in order of frequency: a file with extra rows above the header, a total row at the bottom that is read as data, a column that exists in some files and not others, a sheet renamed in one file, and a file in the folder that is not part of the data — a template, a backup copy, or a file with a tilde in its name from being open elsewhere. Most of these can be handled in the query, but each one needs handling deliberately.

How do I check that combining the files did not lose anything?+

Compare the total row count and a control total. Count the rows per source file and add them up, then compare to the row count of the combined table. Do the same with a numeric column total. If both agree, the combine is arithmetically complete — which is a much stronger check than looking at the output and deciding it looks about right.

Related guides