How to Combine Excel Workbooks While Keeping One Header Row
Question details
The user wants to combine data from multiple Excel workbooks into a single master sheet without duplicating the header row from each source file.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Merging data from several separate workbooks into a consolidated report using a VBA macro.
- Observed behavior
- The current VBA procedure successfully combines the files but incorrectly copies the header row from every single source file into the final dataset.
Ensure all of your source workbooks have an identical column structure and that your master workbook is saved as a Macro-Enabled Workbook (.xlsm).
Use a Boolean Variable in Your VBA Macro
Modify your existing VBA loop to check whether the macro is processing the very first file. If it is, copy the header row; otherwise, skip the header and only copy the data rows.
By introducing a simple Boolean (True/False) variable, you can instruct your VBA script to treat the first workbook differently from the rest. This ensures the header is established once and ignored in subsequent loops.
Open your VBA editor (Alt + F11). At the beginning of your subroutine, declare the variable by typing: Dim OnlyOnce As Boolean
Before the script enters the loop that opens each workbook, set the variable to True by typing: OnlyOnce = True
Inside your loop, replace your standard copy command with an IF statement. Type: If OnlyOnce = True Then [Copy Range starting at A1] Else [Copy Range starting at A2]
Immediately after the copy command inside the loop, set the variable to False by typing: OnlyOnce = False. This ensures all subsequent workbooks will trigger the 'Else' condition and skip row 1.

Combine Files Using Power Query
Power Query is a robust, code-free alternative to VBA for merging files. It automatically handles headers and promotes them correctly without requiring complex scripting.
Merge Workbooks Effortlessly with WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros and provides intuitive data management tools, making it easy to automate repetitive tasks like merging multiple workbooks without duplicating headers.
- 1. Open the VBA Editor: Launch WPS Spreadsheet and press Alt+F11 to open the built-in VBA Editor.
- 2. Insert Your Code: Paste your modified workbook-combining VBA script with the Boolean logic into a new Module.
- 3. Run the Macro: Execute the macro to instantly compile your source files into a single master sheet with perfectly preserved headers.

Frequently Asked Questions
Why does my combined Excel file have multiple header rows?
When looping through multiple files, a basic copy-paste script selects the entire data range including row 1 from every file. You must explicitly tell the script to start from row 2 (e.g., cell A2) for all files after the very first one.
Can I use VBA to combine files from a specific folder?
Yes, you can use the Dir function in VBA to loop through all Excel files within a specified directory path, opening, extracting data, and closing each one sequentially.
How can I remove duplicate header rows if I already combined the files?
If you already ran a script that copied headers, you can easily clean the data by selecting your dataset, applying a Filter (Ctrl+Shift+L), filtering the first column for your header name, and deleting those specific rows.
Does WPS Office support Excel VBA macros?
Yes, WPS Office fully supports standard VBA macros. You can open, edit, and run your Excel .xlsm scripts directly in WPS Spreadsheet without rewriting your code.




