VBA & Macro Problems

Show an Excel Message When Conditional Formatting Changes a Cell Color

Natalie TaylorNatalie Taylor Nov 20, 2026 869 views

Question details

Show a message when a cell meets the condition used by an Excel conditional formatting rule.

Show an Excel Message When Conditional Formatting Changes a Cell Color
Product
Microsoft Excel
Device & OS
not provided
Scenario
An expiration date is conditionally formatted, and the user wants an alert when it falls within a specified date range.
Observed behavior
Conditional formatting changes the cell's appearance but does not directly trigger a VBA event.
Before you start

Check the conditional formatting rule under Home > Conditional Formatting > Manage Rules and note its date range and cell references. The example below assumes the expiration date is in B2 and uses C2 as an available helper cell.

Solution 1Recommended

Monitor a matching helper formula with Worksheet_Calculate

Use this approach to alert when an expiration date is 91 to 180 days away, without repeating the message on every recalculation.

The helper formula reproduces the formatting condition; the macro checks its result rather than detecting the cell color itself. Adjust the formula and references to match your actual rule.

1
Enter the helper formula

In cell C2, enter =AND(ISNUMBER(B2),B2>=TODAY()+91,B2<=TODAY()+180). This returns TRUE when the date in B2 is between 91 and 180 days from today, inclusive.

2
Open the worksheet code module

Right-click the worksheet tab containing B2 and C2, select View Code, and paste the following code into that worksheet's code window: Private Sub Worksheet_Calculate() Static wasTrue As Boolean If IsError(Me.Range("C2").Value) Then wasTrue = False Exit Sub End If If Me.Range("C2").Value = True Then If Not wasTrue Then wasTrue = True MsgBox "The expiration date is 91 to 180 days away." End If Else wasTrue = False End If End Sub

3
Save and enable the macro

Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). When reopening the workbook, enable macros if you trust the file and its source.

4
Test the alert

On the worksheet, enter =TODAY()+100 in B2. If the workbook is not set to calculate automatically, use Formulas > Calculation Options > Automatic or press F9 to recalculate.

Monitor a matching helper formula with Worksheet_Calculate
When the message appears: The message appears when the helper result becomes TRUE, not on every calculation while it remains TRUE. The alert can appear again after the result becomes FALSE and then TRUE, or after Excel resets the VBA state. TODAY() updates when the worksheet recalculates, so the alert is not guaranteed to appear at midnight.
Free Microsoft Office alternative

Manage expiration dates with WPS Spreadsheets

WPS Office is a free, lightweight Office alternative with a familiar interface. Open Excel files in WPS Spreadsheets to work with date formulas and conditional formatting while moving between Office formats. It does not fix Excel's VBA event behavior.

Use formulas and conditional formatting to highlight expiration datesOpen and edit Microsoft Excel XLSX spreadsheetsWork in a familiar spreadsheet interface for an easier transitionUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can Excel VBA detect a conditional formatting color change directly?

A conditional formatting appearance change does not directly trigger a VBA event. Instead, reproduce the rule in a helper cell and check that cell in the worksheet's Worksheet_Calculate event.

How do I change the expiration date range?

Edit the helper formula in C2. For example, replace TODAY()+91 and TODAY()+180 with the desired lower and upper limits, and ensure they match the rule under Home > Conditional Formatting > Manage Rules.

Why does the message appear only once?

The code stores whether the helper result was already TRUE. It alerts again only after the result becomes FALSE and then TRUE, or when the VBA state is reset.

Why doesn't the message appear when I open the workbook?

Make sure macros are enabled for the trusted file and that the code is in the correct worksheet's code module. Then press F9 to recalculate and check whether C2 returns TRUE.