Apply Conditional Table Cell Shading During a Word Mail Merge
Question details
The user needs mail merge table cells to be shaded automatically based on numeric values, with red for values below zero, green for values of at least three, yellow for other numeric values, and white for nonnumeric values, without running a macro manually after each merge.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A Word mail merge document contains a table that requires conditional cell shading according to numeric thresholds in a data source.
- Observed behavior
- A post-merge macro applies the shading correctly when run manually, but the formatting does not apply automatically to generated documents.
Confirm that the data source column used for the shading rule contains numeric values, not text-formatted numbers, and that the mail merge main document has a stable table location that the routine can inspect.
Use the Merge Tools Add-in or Chart Merge to Apply Shading During the Merge
Recommended when you need the formatting to be written automatically to each merged document instead of running a separate macro pass after the merge.
The Merge Tools add-in or a customized Chart Merge procedure can pass each merged output document to a VBA routine while the merge is being processed. This allows table cell shading to be applied before the generated document is finalized.
In Microsoft Word, open the Mailings tab and confirm that the Merge Tools add-in is available in the Add-ins group. If it is not visible, go to File > Options > Add-ins, select COM Add-ins from the Manage list, and click Go to enable it.
In the Merge Tools add-in, choose the merge option or customized Chart Merge procedure that passes the output document to a VBA routine during the merge.
Inside the VBA routine, access the first table in the output document, inspect each cell value, and set the cell shading to red for values below zero, green for values of at least three, yellow for other numeric values, and white for nonnumeric values.
Finish the mail merge and open one generated document to confirm that table cells show the expected shading automatically without a manual macro run.

Run a Post-Merge VBA Macro on the Completed Document
Use this when the Merge Tools add-in is not available and you accept applying shading as a separate step after the merge.
Use WPS Writer for Everyday Mail Merge and Table Formatting
WPS Office provides WPS Writer, a free, lightweight alternative to Microsoft Word. It opens and saves .docx files with high compatibility, includes standard mail merge tools for letters and labels, and offers familiar table shading and formatting options, making it easy to move from Word without losing everyday formatting.

Frequently Asked Questions
Why does my Word mail merge macro only shade table cells when I run it manually?
Standard Word mail merge does not automatically run post-merge VBA routines. The shading can be applied automatically only when the merge is routed through an add-in such as Merge Tools or a customized Chart Merge procedure that invokes the VBA routine during output generation.
What shading rule should I use for the numeric thresholds?
Set red shading for values below zero, green shading for values of at least three, yellow shading for all other numeric values, and white shading for nonnumeric values.
Can I use WPS Writer to apply the same conditional shading during mail merge?
WPS Writer supports standard mail merge and table formatting, but it does not provide the Word-specific Merge Tools add-in. You can open the merged .docx in WPS Writer and use its table formatting tools for manual or semi-automatic adjustments.
What should I check if the VBA routine does not shade the correct cells?
Verify that the table index in the code matches the target table in the merged document and that the cell values are numeric or can be converted to numbers for comparison, because text-formatted numbers may be treated as nonnumeric.




