How to Hide Mail Merge Field Labels When Excel Values Are Blank
Question details
The user needs a way to hide static text labels in a mail merge document whenever the corresponding Excel data field is completely empty.

- Product
- Word Processing
- Device & OS
- not provided
- Scenario
- Creating mail merge documents, such as reference cards or personalized letters, where not all rows in the Excel data source contain values for every column.
- Observed behavior
- Static text labels typed into the document remain visible even when the merged Excel field has no data, leaving unwanted labels (e.g., 'Phylum: ' or 'Donated by: ') floating next to blank spaces.
Ensure that your Excel spreadsheet is properly connected as the data source for your mail merge and that you have already inserted the necessary basic merge fields into your document layout.
Use the MERGEFIELD Before-Text Switch
Modify the merge field codes to include your static label inside the field itself using the '\b' switch, ensuring the label only prints when data exists.
By default, any text you type directly into your document acts as a static label and will print regardless of whether the linked Excel cell is empty. To fix this, you can use the '\b' (before) switch in your field code. This switch tells the word processor to insert specific text immediately before the merged data, but only if the data field is not blank.
Select the inserted merge field in your document and press 'Shift+F9' (or right-click the field and select 'Toggle Field Codes'). The field will change to display its underlying code, looking something like { MERGEFIELD Phylum }.
Click inside the brackets of the field code and add the '\b' switch followed by your desired label text enclosed in quotation marks. For example, modify the code to: { MERGEFIELD Phylum \b "Phylum: " }.
Press the 'F9' key while the field code is selected. This updates the field and switches it back to the normal view.
Delete the original standalone text label you typed directly into the document, as the merge field itself will now dynamically generate that label when required.
Navigate to the Mailings tab and click 'Preview Results'. Browse through a few records to confirm that the label completely disappears when you reach a record with a blank Excel value.

Master Mail Merges with WPS Office Writer
WPS Office Writer offers a highly intuitive Mailings interface that fully supports advanced field codes and switches. Managing blank Excel data in complex merges is seamless and hassle-free.
- 1. Open WPS Writer: Launch WPS Office and open your main mail merge document template.
- 2. Connect Your Excel Source: Navigate to the 'References' or 'Mailings' tab, click 'Open Data Source', and select your Excel spreadsheet.
- 3. Insert and Edit Field Codes: Use 'Insert Merge Field' to place your data. Select the field, press Shift+F9 to toggle field codes, and apply the '\b' switch for dynamic labels.
- 4. Merge the Document: Preview your dynamic labels to ensure blank fields are hidden, then click 'Merge to New Document' or 'Merge to Printer' to finish.

Frequently Asked Questions
Can I add text after a merge field only if it's not blank?
Yes. Just as the '\b' switch adds text before a field, you can use the '\f' (following) switch to add text after a merge field. For example, { MERGEFIELD Weight \f " lbs" } will only append 'lbs' if the Weight field contains data.
Why isn't my mail merge field updating after I change the code?
After modifying a field code manually, you must force the document to refresh it. Select the field and press 'F9', or right-click the field and choose 'Update Field'. Ensure you have 'Preview Results' turned on to view the updated dynamic text.
Will this method work if the Excel cell contains a space instead of being completely empty?
No. If your Excel cell contains a blank space character, the mail merge processor will consider it a valid text entry (non-blank) and display the label. Ensure your empty Excel cells are truly empty, or use the 'Find and Replace' tool in Excel to clear lingering space characters before merging.




