Document Editing Problems

How to Use Word Merge Fields to Control Tables and Sections

Huma Ashraf ChHuma Ashraf Ch Oct 26, 2026 868 views

Question details

The user needs to display different table rows or document sections during a Word mail merge based on an equipment type stored in a merge field.

How to Use Word Merge Fields to Control Tables and Sections
Product
Word
Device & OS
not provided
Scenario
Setting up a mail merge document that requires conditional formatting, specifically trying to use IF statements to control table outputs based on specific data values.
Observed behavior
When nesting a TableEnd field inside an IF statement, the formula fails to evaluate properly, ending the table prematurely even when the condition is not met.
Before you start

Ensure your data source is fully updated, cleanly formatted, and connected to your document before inserting conditional field codes.

Solution 1Recommended

Use IF Fields to Conditionally Display Content

Use Word's built-in IF fields combined with Merge Fields to show or hide plain text or document sections based on specific data values.

The IF field compares two values and inserts appropriate text based on the result. When combined with mail merge, it allows you to personalize the document based on the recipient's specific data.

1
Reveal Field Codes

Press 'Alt + F9' on your keyboard to toggle the display of field codes in your Word document.

2
Insert Field Brackets

Press 'Ctrl + F9' to insert a new pair of blank field brackets { }. Do not type these manually with the keyboard, as they will not be recognized as field codes.

3
Write the IF Statement

Inside the brackets, type your condition. For example: { IF { MERGEFIELD EquipmentType } = "Laptop" "Include this section for laptops" "Include this section for other equipment" }.

4
Update and Preview

Press 'Alt + F9' again to hide the codes. Highlight the field, press 'F9' to update it, and click 'Preview Results' in the Mailings tab to verify the logic.

Use IF Fields to Conditionally Display Content
Syntax Formatting: Ensure you place quotation marks around strings with multiple words and maintain proper spacing inside the brackets.
Efficient Mail Merge

Perform Conditional Mail Merge Seamlessly with WPS Writer

WPS Writer offers an intuitive and powerful Mail Merge feature that makes it easy to connect complex data sources and generate dynamic documents without wrestling with formatting errors.

  1. 1. Open the Mailings Tab: Launch WPS Writer, create a new document, and click on the 'References' or 'Mailings' tab on the top ribbon.
  2. 2. Connect Data Source: Click 'Open Data Source' to select your Excel spreadsheet or database containing the equipment information.
  3. 3. Insert Fields and Logic: Place your cursor in the document, select 'Insert Merge Field', and utilize 'Word Fields' to add IF...THEN...ELSE rules easily.
  4. 4. Complete the Merge: Click 'Merge to New Document' to generate your conditionally formatted pages based on the imported rules.
Full compatibility with Microsoft Word (.docx) formats and field codesIntuitive Mail Merge wizard for straightforward data integrationFree and lightweight software that handles large datasets smoothly
microsoft office alternative - wps office

Frequently Asked Questions

Why is my TableEnd field not working inside an IF statement?

Word's mail merge engine processes structural fields like TableStart and TableEnd differently than standard text. When nested inside an IF statement, the engine often evaluates the table structure before assessing the IF logic, causing the table to end prematurely. It is recommended to wrap whole tables in IF fields rather than placing TableEnd tags inside them.

Can I use multiple conditions in a Word IF field?

Yes, but Word does not natively support AND/OR operators in IF fields. To check multiple conditions, you must nest IF fields inside one another. For example, place a second IF statement inside the 'TrueText' section of the first IF statement.

How do I edit my IF statement manually after creating it?

To manually edit field codes in Word or WPS Writer, press Alt + F9 on Windows (or Option + F9 on Mac). This toggles the view from the result to the underlying field code structure { IF ... }. Make your changes, press Alt + F9 to close, and press F9 to update the field.

What does a blank result mean in an IF field?

A blank result usually means the condition was not met and you did not provide any 'FalseText' (the text to display when the condition is false), or there is a syntax error such as missing spaces around the equals sign or missing quotation marks.