When you run a mail merge in Word, records that contain empty fields can create unwanted blank lines, missing addresses, or awkward spacing in your merged documents. This happens because Word keeps the empty field placeholder in the output, leaving a gap where data should appear. This article explains how to use the If…Then…Else field code to skip records with empty fields so your letters, labels, or envelopes print cleanly without gaps.
Key Takeaways: Skip Empty Fields in Mail Merge
- Insert Merge Field > If…Then…Else: Replaces empty fields with nothing so no blank line appears in the merged document.
- Toggle field codes with Alt+F9: Shows the underlying field code so you can edit the IF statement to check for blank data.
- Preview Results button: Lets you test the merge before printing to confirm empty records are skipped correctly.
How Mail Merge Handles Empty Fields
Mail merge pulls data from a source like an Excel spreadsheet, Outlook contacts, or an Access database. When a field in the source is blank, Word inserts nothing in its place. However, the paragraph mark or line break that surrounds the field remains. This leaves a blank line in the merged output. For example, if a contact has no company name, the address block may show a gap between the name and street address.
The root cause is that Word does not automatically suppress empty fields. It treats each merge field as a placeholder that always occupies space in the document structure. The solution is to use the If…Then…Else field code to test whether a field contains data. If it is blank, the field outputs nothing and the surrounding paragraph break is suppressed.
Steps to Apply the If…Then…Else Field Code
These steps use Word for Microsoft 365, Word 2021, and Word 2019. The process is identical in Word 2016 and Word 2013.
- Open your mail merge main document
Start from an existing mail merge document or create one using Mailings > Start Mail Merge. Choose Letters, E-mail Messages, Envelopes, or Labels. Connect to your data source. - Insert the merge field you want to conditionally skip
Place the cursor where the field should appear. Go to Mailings > Insert Merge Field and select the field name, for example Company. The field appears as «Company». - Convert the merge field to an IF field
Press Alt+F9 to display field codes. The «Company» field shows as { MERGEFIELD Company }. Delete this code and replace it with the following IF statement:{ IF "{ MERGEFIELD Company }" = "" "" "{ MERGEFIELD Company }" }
This tells Word: if the Company field is blank, output nothing; otherwise, output the Company value. - Press Alt+F9 again to hide field codes
The field now displays the merge field name again, but it is wrapped in the IF logic. - Repeat for each field that may be empty
Apply the same IF structure to every field that could be blank, such as Address Line 2, Middle Name, or Phone Extension. Adjust the field name inside the MERGEFIELD part of the code. - Test the merge with Preview Results
Click Mailings > Preview Results. Scroll through several records to confirm that blank fields produce no extra lines. If you see a blank line, the paragraph mark after the field is still present. You need to move the IF field so it includes the paragraph break. - Suppress the paragraph break for empty fields
Select the paragraph mark (¶) that follows the field. Press Alt+F9 to see the field code. Cut the paragraph mark and paste it inside the IF field after the second set of quotes. The code becomes:{ IF "{ MERGEFIELD Company }" = "" "" "{ MERGEFIELD Company }¶" }
The paragraph mark only appears when the field is not blank. - Finish the merge
Click Mailings > Finish & Merge > Edit Individual Documents or Print Documents. The output will contain no blank lines for empty fields.
Common Pitfalls and How to Avoid Them
The IF field code shows an error when previewing
If you see “!Syntax Error,” the field code is missing a quotation mark or curly brace. Check that every opening curly brace has a matching closing brace. In Word, you cannot type curly braces manually. You must insert a field code using Ctrl+F9 to create a valid pair of braces. Delete your IF field, press Ctrl+F9 to insert an empty field, then paste the IF code inside the braces.
Blank lines still appear after applying the IF field
The IF field only controls the field value, not the paragraph mark after it. To remove the blank line, you must move the paragraph mark inside the IF field as shown in step 7. If you have multiple fields on the same line, each one must be wrapped individually with its own IF statement.
The IF field works in Preview but not in the final merge
This usually happens when the data source contains spaces or invisible characters instead of truly blank cells. Clean your data source by using the TRIM function in Excel to remove extra spaces. Then re-run the merge.
Mail Merge Field Suppression: IF Field vs Manual Deletion
| Item | IF Field Code | Manual Deletion |
|---|---|---|
| Setup time | 5–10 minutes per document | Instant for one record |
| Scalability | Works for thousands of records | Must edit each record individually |
| Blank line suppression | Automatic when field is empty | Not possible in bulk |
| Requires field code editing | Yes | No |
| Works with all merge types | Yes (letters, labels, envelopes) | Only for single-record documents |
Using the IF field code is the only reliable method to skip records with empty fields in a mail merge. Manual deletion does not scale and cannot be automated. Once you set up the IF field, it works for every record in your data source without further intervention.
After you apply the IF field code, test your merge with at least three records that have blank fields. If the output looks correct, run the full merge. For advanced control, combine multiple IF fields inside one address block to handle missing city, state, or ZIP fields. You can also use nested IF fields to check multiple conditions, such as skipping a line only when both Company and Title are blank.