Replace Excel Conditional Formatting With a VBA Macro
Question details
The user wants to replace slow conditional formatting with a VBA macro that applies formatting on demand.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A workbook uses conditional formatting, and the user wants to refresh equivalent direct formatting periodically, such as once per week.
- Observed behavior
- The user wants the macro to apply the relevant formatting when run rather than rely on continuously evaluated conditional formatting rules.
Review the rules and their ranges under Home > Conditional Formatting > Manage Rules. Identify the conditions and formatting you want the macro to reproduce, and make sure the target cells do not contain fills you need to retain.
Apply Direct Formatting With an Excel VBA Macro
Use this approach to refresh a specific formatting rule manually instead of having Excel evaluate it continuously.
The example highlights cells containing Holiday in yellow and removes the fill from other cells in A2:A1000 on the active worksheet. Adapt the range, condition, and formatting to match your rules; more complex rules may require additional VBA logic.
In Excel, press Alt+F11, or open Developer > Visual Basic. In the VBA editor, select Insert > Module.
Paste this code into the module: Sub ApplyWeeklyFormatting() Dim cell As Range For Each cell In ActiveSheet.Range("A2:A1000") If cell.Value = "Holiday" Then cell.Interior.Color = RGB(255, 255, 0) Else cell.Interior.Pattern = xlNone End If Next cell End Sub
Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Return to the target worksheet, open Developer > Macros, select ApplyWeeklyFormatting, and click Run. Check that the results match the intended rule.
After testing, select Home > Conditional Formatting > Manage Rules. Find the rule the macro replaces, select it, click Delete Rule, and apply the change. Leave unrelated rules in place.
Activate the target worksheet and run ApplyWeeklyFormatting from Developer > Macros whenever you want to update the colors, such as once per week.

Work With Formatted Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday workbook editing to WPS. Check VBA support and test macros before migrating macro-dependent files.

Frequently Asked Questions
Will the macro update the colors when a cell value changes?
No. Select the target worksheet and run ApplyWeeklyFormatting from Developer > Macros to refresh the colors after values change.
How do I change which cells the macro checks?
In the VBA editor, change ActiveSheet.Range("A2:A1000") to the range you want to format. Activate the intended worksheet before running the macro.
Can I keep other conditional formatting rules?
Yes. Open Home > Conditional Formatting > Manage Rules and delete only the rules the macro replaces. Other rules can remain, although they may affect the displayed formatting.
Why should I save the workbook as an XLSM file?
The XLSM format retains VBA macros. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm); a standard XLSX file cannot retain the macro.
Will removing conditional formatting always make the workbook faster?
Not necessarily. Performance depends on the number and complexity of rules and other workbook calculations. Test the workbook after replacing the relevant rules to see whether it improves.




