VBA & Macro Problems

Replace Excel Conditional Formatting With a VBA Macro

John WilsonJohn Wilson Nov 18, 2026 870 views

Question details

The user wants to replace slow conditional formatting with a VBA macro that applies formatting on demand.

Replace Excel Conditional Formatting With a VBA Macro
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11, or open Developer > Visual Basic. In the VBA editor, select Insert > Module.

2
Add the macro

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

3
Save and test

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.

4
Remove the replaced 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.

5
Refresh when needed

Activate the target worksheet and run ApplyWeeklyFormatting from Developer > Macros whenever you want to update the colors, such as once per week.

Apply Direct Formatting With an Excel VBA Macro
Formatting is not updated automatically: The macro replaces existing fills in the target range and does not run on a schedule by itself. Changes to cell values will not be reflected in the colors until you run it again.
Free Microsoft Office alternative

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.

Edit and format spreadsheet cells in WPS SpreadsheetsOpen and save common Microsoft Excel formats, including XLSX and XLSUse a familiar interface for everyday workbook tasksMove routine spreadsheet work to a free, lightweight office suite
microsoft office alternative - wps office

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.