Document Editing Problems

How to Remove Blank Mail Merge Rows and Create Individual Word Files

Olivia MillerOlivia Miller Oct 28, 2026 870 views

Question details

The user needs to remove empty table rows generated during a mail merge when records are fewer than the table's capacity, and wants to save each merged customer record as an individual file.

How to Remove Blank Mail Merge Rows and Create Individual Word Files
Product
Word
Device & OS
not provided
Scenario
Creating invoices or forms using mail merge where the number of items per customer varies, resulting in unwanted blank rows and a need for separate output files.
Observed behavior
The mail merge creates empty rows to fill the maximum table size, and generates a single combined document instead of individual files per customer.
Before you start

Ensure your main mail merge document is correctly linked to your data source, and make a backup copy of your document before running macros or installing external add-ins.

Solution 1Recommended

Use a VBA Macro to Delete Blank Rows Post-Merge

Run a VBA macro on the merged output document to automatically detect and delete rows that contain no text.

This macro is executed after the standard mail merge is completed. It targets the newly generated document and scans all tables, removing only the rows that are completely empty.

1
Execute the Mail Merge

Perform your standard mail merge to generate a new document containing all records.

2
Open the VBA Editor

Press Alt + F11 to open the Microsoft Visual Basic for Applications window, then click Insert > Module.

3
Paste the Macro Code

Copy and paste the following code: Sub MailMergeToDoc() Application.ScreenUpdating = False Dim tbl As Table, r As Long ActiveDocument.MailMerge.Execute For Each tbl In ActiveDocument.Tables For r = tbl.Rows.Count To 1 Step -1 If Len(tbl.Rows(r).Range.Text) = tbl.Rows(r).Cells.Count * 2 + 2 Then tbl.Rows(r).Delete Next r Next tbl Application.ScreenUpdating = True End Sub

4
Run the Macro

Press F5 or click the Run button to execute the script and clean up the blank rows.

Use a VBA Macro to Delete Blank Rows Post-Merge
Macro Limitations: The macro only deletes rows that are entirely empty. Rows containing formulas, hidden spaces, or other invisible content will remain untouched.
WPS Office Solution

Easily Handle Mail Merges and Separate Files in WPS Writer

WPS Writer streamlines the mail merge process by natively supporting the splitting of merged documents into individual files without requiring external add-ins. You can also run standard VBA macros to automate row cleanup.

  1. 1. Start Mail Merge: Open your template in WPS Writer, go to the Mailings tab, and click Open Data Source to link your spreadsheet.
  2. 2. Split the Document: After inserting your merge fields, click on 'Merge to Different New Document' on the ribbon.
  3. 3. Run Cleanup Macros: Use the built-in Developer tab to access the VBA Editor and run scripts to remove any leftover blank rows.
Native 'Merge to Different New Document' feature to save separate files instantly.Fully compatible with Microsoft Word .docx formats and mail merge fields.Built-in VBA editor (in Pro versions) to seamlessly run your formatting macros.Lightweight, fast, and easy to use.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my mail merge leave blank rows in the invoice table?

When your Word document table is built with a fixed maximum number of rows, customers who have fewer items will leave the remaining rows empty during the mail merge process.

Can I merge directly to individual PDF files instead of Word documents?

Yes. By using the Merge Tools Add-in or using the built-in splitting features in software like WPS Office, you can set the output format to save each merged customer record as an individual PDF.

Will the VBA macro delete rows that contain formulas?

No, the provided VBA macro is specifically written to delete only rows that are completely empty. If a row contains hidden formulas, spaces, or other non-visible characters, it will not be deleted.