Stop manually copying data between Excel files. This hands-on lesson walks you through building a production-ready Power Automate Desktop flow that loops through every workbook in a folder, reads each dataset into a DataTable, and appends all rows into a single consolidated output — no macros required.

Every month, the regional sales managers send in their numbers. Each one submits an Excel workbook: NorthEast_Sales_March.xlsx, SouthWest_Sales_March.xlsx, Midwest_Sales_March.xlsx, and so on. Your job is to pull all of those files together into a single consolidated workbook so finance can run their analysis. If you're doing this manually, you're opening each file, copying the data, switching to your master sheet, finding the last row, pasting, closing the source file, and repeating — maybe a dozen times, maybe fifty. It's tedious, error-prone, and completely automatable.
Power Automate Desktop gives you everything you need to build this consolidation pipeline without writing a single macro. You can loop through every file in a folder, read the data into a DataTable, track your running row position in the output file, write each batch of rows in sequence, and produce a clean, formatted combined workbook — all in a flow that runs in minutes rather than hours. The result is repeatable, auditable, and runs just as cleanly on a Tuesday morning as it does during a Friday afternoon crunch.
By the end of this lesson, you'll have built a production-ready workbook consolidation flow from scratch. You'll understand not just the mechanics of each action, but why the architecture is built the way it is — so you can adapt it to your own data scenarios.
What you'll learn:
You should already be comfortable with the basics of Power Automate Desktop — if you're brand new, start with Getting Started with Power Automate Desktop: Installing, Recording, and Running Your First Desktop Flow before continuing here.
You'll also benefit from reviewing Variables, Lists, and Data Tables in Power Automate Desktop: A Complete Practitioner's Guide since DataTables are central to this flow. And if you want deeper context on Excel actions specifically, Automating Excel with Power Automate Desktop: Reading, Writing, and Running Macros covers the fundamentals we'll be building on.
For this lesson, you need:
.xlsx files with consistent column structures (we'll use a sales reporting scenario)Before you touch the flow designer, it's worth modeling the problem. Workbook consolidation has four distinct phases:
Each phase maps to a section of your flow. Getting the architecture right up front means you won't be untangling a 200-action flat flow when something goes wrong. We'll implement Discovery and Extraction in the main flow loop, Consolidation in a subflow, and Finalization at the end of Main.
Our scenario: You have a folder at C:\SalesReports\Monthly\Input\ containing files like NorthEast_Sales_March.xlsx, SouthWest_Sales_March.xlsx, and Midwest_Sales_March.xlsx. Each file has one sheet called SalesData with columns: Region, Rep Name, Product SKU, Units Sold, Revenue, Month. The output goes to C:\SalesReports\Monthly\Output\Consolidated_March.xlsx.
Note
The column structure must be consistent across all source files for this approach to work correctly. If your source files have different column orders or names, you'll need to add a normalization step before writing. We'll address that in the troubleshooting section.
Open Power Automate Desktop and create a new flow called Consolidate Monthly Sales. The first action you need is Get files in folder from the File group.
Configure it like this:
C:\SalesReports\Monthly\Input*.xlsxThis action produces a list variable — name it ExcelFileList. Each item in this list is a file object with properties like FullName, Name, Size, and Extension.
Next, initialize the variables you'll use throughout the flow. Use Set variable actions for each:
| Variable | Initial Value | Purpose |
|---|---|---|
OutputFilePath |
C:\SalesReports\Monthly\Output\Consolidated_March.xlsx |
Path to the output workbook |
WriteRow |
1 |
Tracks the next row to write in the output |
IsFirstFile |
True |
Controls whether we write the header row |
FileCount |
0 |
For logging/diagnostics |
Tip
Initializing WriteRow to 1 means your first write goes to row 1. If you want a title row above the headers, start at 2 and handle row 1 separately after the loop — but for most consolidation tasks, row 1 as the header keeps things clean.
Now create the output workbook before entering the loop. Use Launch Excel with:
OutputExcelInstanceThen immediately save it to establish the file on disk. Use Save Excel with the OutputExcelInstance, choosing Save document as and pointing to OutputFilePath with format xlsx. This gives you a file you can reference consistently throughout the flow.
Now add a For each loop over ExcelFileList. Inside this loop is where the real work happens. Store the current file object in CurrentFile.
The first action inside the loop should increment your counter:
SET FileCount TO FileCount + 1
Then launch the source workbook:
Launch Excel action:
%CurrentFile.FullName%SourceExcelInstanceWarning
Always use %CurrentFile.FullName% rather than %CurrentFile.Name% here. FullName includes the complete path; Name is just the filename. Using Name without a path will cause Excel to look in the working directory, which is almost certainly not where your files are.
After launching, you need to activate the correct worksheet. Use Set active Excel worksheet with:
SourceExcelInstanceSalesDataThis is important even if the workbook only has one sheet — if someone accidentally renamed the tab or added a summary sheet in front, explicitly naming the target sheet prevents silent data reads from the wrong place.
Now read the actual data. Use Read from Excel worksheet with:
SourceExcelInstanceSourceDataTableTurning on "First line contains column names" means your DataTable will have named columns matching your headers, and the first actual data row will be index 0. This is what you want — but it means you need to handle headers separately when writing to the output file.
After reading, check that you actually got data. Add a Get DataTable column into list action to extract any column (say Region) and check the list length — or more directly, use an If condition:
IF SourceDataTable.RowsCount = 0 THEN
-- Log this and continue to next file
NEXT LOOP
END
In PAD, you implement this with a Get DataTable dimensions action (which gives you row and column counts) and then an If block checking RowCount = 0. If true, add a Go to next loop iteration action and skip the rest of the processing. An empty file shouldn't crash your flow — it should just be noted and skipped.
Key insight
Read from Excel worksheet with "First line contains column names" enabled strips the header from the DataTable. The RowsCount reflects only data rows. This means a file with only a header row and no data returns RowsCount = 0, which is exactly what you want to detect and skip.
This is where IsFirstFile earns its keep. Inside an If block checking IsFirstFile = True:
Switch to your output instance and write the column headers. The cleanest way to do this in PAD without macros is to write each header cell individually using Write to Excel worksheet:
OutputExcelInstanceRegionA%WriteRow%Repeat for each column: B for Rep Name, C for Product SKU, D for Units Sold, E for Revenue, F for Month.
After writing headers, increment WriteRow by 1:
SET WriteRow TO WriteRow + 1
Then set IsFirstFile to False so subsequent files skip this block entirely.
Tip
If your column count is large (10+ columns), consider building the header row using a Write to Excel worksheet action in a small For Each loop over a predefined list of column names. Create a list called Headers with values ['Region', 'Rep Name', 'Product SKU', 'Units Sold', 'Revenue', 'Month'] and loop through it with a column counter. This is far easier to maintain than 15 individual write actions.
Now you write the actual data rows from SourceDataTable into the output file. This is best handled in a dedicated subflow — both for readability and because you may want to reuse this logic. If you haven't used subflows before, [Subflows and Reusable Logic in Power Automate Desktop](/articles/subflows-and-reusable-logic-in-power-automate Desktop) covers how to create them and pass variables between them.
Create a subflow called WriteDataTableToOutput. It receives (conceptually — PAD doesn't have true subflow parameters, so you'll use the shared flow variables) SourceDataTable, OutputExcelInstance, and WriteRow.
Inside WriteDataTableToOutput, add a For each loop over SourceDataTable with the current row stored in CurrentRow:
For each data row, write each cell value to the appropriate column in the output file. The key is using %WriteRow% as the row number so each iteration advances to the next line:
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Region']%
Column: A
Row: %WriteRow%
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Rep Name']%
Column: B
Row: %WriteRow%
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Product SKU']%
Column: C
Row: %WriteRow%
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Units Sold']%
Column: D
Row: %WriteRow%
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Revenue']%
Column: E
Row: %WriteRow%
Write to Excel worksheet
Excel instance: OutputExcelInstance
Value: %CurrentRow['Month']%
Column: F
Row: %WriteRow%
SET WriteRow TO WriteRow + 1
The WriteRow increment at the bottom of each iteration is critical. Without it, every row overwrites the same cell. The variable persists across loop iterations because it's defined at the flow level — meaning it also correctly accumulates across multiple files. When file two starts writing, WriteRow is already sitting at the next empty row after file one's data. That's the entire mechanism that makes multi-file append work.
Warning
Writing cell-by-cell is reliable but slow for large datasets. A file with 500 rows and 6 columns means 3,000 individual write actions per file. For high-volume scenarios, consider using Write to Excel worksheet with a DataTable value directly in "Write value at" mode on a starting cell — PAD will write the entire table in one action. We cover the tradeoffs of this approach in the troubleshooting section below.
After calling WriteDataTableToOutput (using Run subflow), close the source workbook cleanly:
Close Excel action:
SourceExcelInstanceYou never want to save changes to source files — always close without saving. If the source file was read-only or had any formatting changes triggered by simply opening it (AutoRecalc, conditional formatting evaluation, etc.), you don't want those flushed back to disk.
After closing, the loop continues to the next file in ExcelFileList. Because WriteRow and IsFirstFile are flow-level variables, they carry their state forward correctly into the next iteration.
For error handling in desktop flows, wrap your Launch Excel and Read from Excel worksheet actions in an On block error handler. If a file is corrupted, locked by another user, or has an unexpected structure, you want the flow to log the filename and continue — not crash and lose all the work done on previous files.
Inside the error block:
SET ErrorLog TO ErrorLog + NewLine + 'Failed to process: ' + CurrentFile.Name
NEXT LOOP
Initialize ErrorLog as an empty text variable before the loop starts, and write it to a text file at the very end of the flow. This gives you a clean audit trail without manual intervention. You can read more about automating file, folder, and email operations to handle the log file writing.
After the For Each loop over ExcelFileList completes, you have all the data in OutputExcelInstance. Now save and close cleanly.
First, optionally auto-fit the columns. Without macros, PAD doesn't have a native "auto-fit columns" action — but you can approximate it by making Excel visible and using a keyboard shortcut sequence, or simply accept that the user will auto-fit manually when they open the file. For fully automated, unattended runs, the data integrity matters more than column width.
Save the output file:
Save Excel action:
OutputExcelInstanceThen close it:
Close Excel action:
OutputExcelInstanceFinally, write your completion message. Use Display message for attended flows, or write a status entry to your log file for unattended runs. Include FileCount and WriteRow in the message so you know how many files were processed and how many total data rows were written:
Consolidation complete.
Files processed: %FileCount%
Total data rows written: %WriteRow - 1%
(WriteRow - 1 because WriteRow points to the next empty row, not the last written row)
Note
For unattended RPA scenarios, replace the Display message with a Write text to file action logging completion status. If this flow is triggered from a cloud flow, you can also return FileCount and WriteRow as output variables. See Triggering Desktop Flows from Cloud Flows: Passing Inputs and Returning Outputs for how to wire that up.
There's a faster alternative to cell-by-cell writing worth understanding. PAD's Write to Excel worksheet action has a mode where, instead of writing a single value, you point it at a DataTable variable. PAD then writes all rows and columns in a single operation — dramatically faster for large datasets.
The configuration looks like this:
Write to Excel worksheet action:
OutputExcelInstance%SourceDataTable%A%WriteRow%After this single action, PAD writes all rows from SourceDataTable starting at the specified cell. You then need to advance WriteRow by the number of rows written:
SET WriteRow TO WriteRow + SourceDataTable.RowsCount
This is elegant and fast. The tradeoff: you lose individual row control. If a specific row has a data type issue — a revenue field that contains text, for instance — the entire DataTable write may behave unexpectedly. Cell-by-cell writing lets you catch and handle individual row problems. For clean, trusted data sources, the DataTable write approach is worth using. For messier real-world data, the row-by-row approach gives you more control.
For header handling with the DataTable approach, the logic is identical — write headers on the first file, skip them on subsequent files, and use WriteRow to track your position. The only difference is that WriteRow advances by SourceDataTable.RowsCount rather than incrementing by 1 inside a loop.
Some source workbooks won't be as simple as "one sheet, full data starting at A1." Real-world files often have metadata in the first few rows, data starting at A5, or relevant data split across multiple named sheets.
For working with Excel ranges, sheets, and named cells, the Read from Excel worksheet action lets you specify a range explicitly. Instead of "All available values," choose "Values from a range of cells" and specify:
A, Start row: 5F, End row: (leave blank to read to the last row)This skips the first four rows of metadata and reads only the data range. Combined with "First line of range contains column names: On," you can handle files with preamble rows cleanly.
For multi-sheet scenarios, loop over the sheet names. Use Get worksheets to retrieve all sheet names from SourceExcelInstance, then loop through that list and process each one — just be careful to skip summary or reference sheets by name.
Build this flow from scratch against your own data. If you don't have sales files ready, create three simple test workbooks manually:
File 1: NorthEast_Sales_March.xlsx — Sheet name: SalesData
Region | Rep Name | Product SKU | Units Sold | Revenue | Month
NorthEast | Alice Johnson | SKU-1042 | 120 | 14400.00 | March
NorthEast | Bob Martinez | SKU-2017 | 85 | 10710.00 | March
NorthEast | Carol White | SKU-1042 | 200 | 24000.00 | March
File 2: SouthWest_Sales_March.xlsx — Sheet name: SalesData
Region | Rep Name | Product SKU | Units Sold | Revenue | Month
SouthWest | David Kim | SKU-3301 | 60 | 9600.00 | March
SouthWest | Emma Torres | SKU-2017 | 145 | 18270.00 | March
File 3: Midwest_Sales_March.xlsx — Sheet name: SalesData
Region | Rep Name | Product SKU | Units Sold | Revenue | Month
Midwest | Frank Lee | SKU-1042 | 95 | 11400.00 | March
Midwest | Grace Patel | SKU-3301 | 170 | 27200.00 | March
Midwest | Henry Brown | SKU-2017 | 110 | 13860.00 | March
Your tasks:
Build the flow as described in this lesson. Run it and verify that Consolidated_March.xlsx contains all 8 data rows with the header appearing exactly once.
Add a fourth "bad" file — Broken_Sales_March.xlsx — that has an empty SalesData sheet. Verify your flow skips it and continues without crashing.
Modify the flow to also write a SourceFile column to the output, capturing CurrentFile.Name for each row. This is a common audit requirement — knowing which source file each row came from.
Add a file-level timestamp. After all files are processed, add a row at the very bottom of the output with the text Generated: followed by the current datetime. Use the Get current date and time action.
Extend the flow to send an email notification when consolidation is complete, attaching the output file. Build this as a separate subflow called SendCompletionEmail.
Symptom: The output file only contains data from the last file processed.
Cause: WriteRow is being reset to 1 at the start of each loop iteration — usually because you have a Set variable action for WriteRow inside the loop instead of before it.
Fix: Move WriteRow initialization (SET WriteRow TO 1) to before the For Each loop, not inside it. Inside the loop, you should only be reading and incrementing WriteRow, never resetting it.
Symptom: The output has headers, then 3 rows of data, then headers again, then 3 more rows.
Cause: IsFirstFile is either never being set to False, or it's being re-initialized inside the loop.
Fix: Confirm that your SET IsFirstFile TO False action is inside the IF IsFirstFile = True block, runs after writing headers, and that you haven't accidentally placed SET IsFirstFile TO True inside the loop.
Symptom: The Launch Excel action fails with a file not found error even though the file exists.
Cause: Almost always using %CurrentFile.Name% instead of %CurrentFile.FullName%.
Fix: Always use %CurrentFile.FullName% for the document path in Launch Excel.
Symptom: When using the DataTable write approach, the first data row is missing from the output.
Cause: "First line of range contains column names" was enabled when reading, which is correct. But you may have also manually written the headers starting at WriteRow = 1, then incremented WriteRow to 2 — and then written the DataTable starting at row 2. The DataTable doesn't include headers, so row 2 in the output is correctly your first data row. This is actually working as intended. If you're seeing a gap, check that you incremented WriteRow after writing headers.
Symptom: The flow errors on a file that has headers but no data rows.
Cause: No empty-file check before attempting to write data.
Fix: After reading the DataTable, add: Get DataTable dimensions → store row count in SourceRowCount → IF SourceRowCount = 0 THEN → Go to next loop iteration. This skips empty files gracefully.
Symptom: Excel shows a "file is already open" dialog on subsequent runs.
Cause: The flow crashed midway through a previous run, leaving Excel instances open without being closed.
Fix: Add error handling around the entire file-processing block. In the error handler, include a Close Excel action for SourceExcelInstance before continuing. Also consider automating Windows dialog boxes and pop-up windows to handle the "file already open" prompt if it appears.
Symptom: Some rows in the output have blank cells, or values appear in the wrong columns.
Cause: Source files have different column orders or different column names on the header row.
Fix: Use explicit column name access (%CurrentRow['Revenue']%) rather than positional access. If column names differ across files, add a normalization step: after reading the DataTable, rename columns using a lookup to map source names to canonical names. This is an advanced requirement that may also warrant adding a validation subflow that checks column names before processing begins.
Key insight
Using named column access (%CurrentRow['Revenue']%) instead of positional access (%CurrentRow[4]%) makes your flow resilient to column reordering. It's a small choice that prevents a category of bugs entirely.
For folders with fewer than 20 files and datasets under 1,000 rows per file, the cell-by-cell approach works fine and typically completes in under a minute. As you scale up, consider these strategies:
Use DataTable bulk writes for clean, trusted datasets. A 500-row DataTable writes in roughly the same time as 5-10 individual cell writes.
Keep Excel hidden. Make Excel visible: Off on your Launch Excel actions eliminates the rendering overhead of drawing the Excel UI. This alone can halve processing time for large files.
Process on a machine with enough RAM. Large DataTables consume memory. If you're processing dozens of files with thousands of rows each, monitor memory usage. PAD runs in-process, so very large DataTables can cause slowdowns.
Consider whether PAD is the right tool for extreme scale. For consolidating hundreds of multi-megabyte workbooks, a PowerShell script using the ImportExcel module or a Python script with openpyxl may outperform PAD significantly. PAD is the right choice when the task needs to run on a standard business machine, requires no developer toolchain, or sits within a broader automation that includes UI interactions. The scripting inside desktop flows approach lets you call PowerShell from within your PAD flow if you need to hybrid the two.
You've built a complete, production-ready Excel consolidation flow in Power Automate Desktop — without touching a macro or writing a line of VBA. The flow discovers files dynamically, reads each workbook's data into a DataTable, tracks its write position across files, writes headers exactly once, appends all data rows in sequence, and closes both source and output workbooks cleanly. You've also wired in empty-file detection and error handling so the flow degrades gracefully rather than crashing.
The architecture here — a discovery loop, an extraction-and-write pattern using a row counter variable, and a subflow for the write logic — is reusable far beyond sales consolidation. Any scenario where you're pulling data from multiple same-structure files into a single output follows this exact pattern.
Where to go next:
The skills you've built here — dynamic file enumeration, DataTable manipulation, and careful state tracking with variables — are the foundation of virtually every complex desktop automation you'll build. Master this pattern, and you'll recognize it in dozens of future problems.
Power Automate Desktop & RPA