How to Highlight Excel Rows Only When Values Change Using VBA
Question details
The user needs to highlight rows in a spreadsheet only when a cell's value genuinely changes, avoiding highlights for edits where the value remains identical to its previous state.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Tracking weekly changes (such as prices for hundreds of products) where rows need to be visually flagged only upon actual data modification, without relying on standard edit-triggered macros.
- Observed behavior
- A standard Worksheet_Change macro highlights the row whenever a cell is edited, even if the user reverts the change or types the same value. Furthermore, it retains the highlight indefinitely unless explicitly cleared.
Ensure your dataset includes a unique identifier column (like a Product ID or Row Key) so that values can be accurately matched and compared, even if rows are sorted or inserted.
Use a Baseline Reference Sheet with a VBA Macro
Store the original values in a separate reference sheet and use a macro to compare current values against this baseline, highlighting only the rows with actual differences.
Because Excel cannot inherently remember previous cell values once they are overwritten, a Worksheet_Change event cannot distinguish between a real change and an identical re-entry. Using a separate baseline sheet solves this by providing a historical reference point for comparison.
At the start of your tracking cycle (e.g., weekly), duplicate your main data sheet. Name the duplicate sheet 'Baseline' to store the original values.
Press 'Alt + F11' to open the Visual Basic for Applications (VBA) editor, then click 'Insert' > 'Module' to create a new script area.
Write a VBA script that loops through the rows in your main sheet. The code should use the unique Product ID to find the matching row in the 'Baseline' sheet and compare the target values (e.g., Prices).
In your script, include a command to clear existing highlights ('Cells.Interior.ColorIndex = xlNone') before the loop. Inside the loop, add an 'If' statement so that if the current value does not match the baseline value, the macro applies a highlight using 'Row.Interior.Color'.
Close the VBA editor and run the macro from the 'Developer' tab by clicking 'Macros', selecting your new script, and clicking 'Run'.

Use Conditional Formatting as a Non-VBA Alternative
If you prefer not to use macros, you can use Conditional Formatting to dynamically highlight rows by comparing them to a reference sheet.
Track Value Changes Easily with WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros and advanced conditional formatting, enabling you to automate data tracking and highlight changed rows seamlessly.
- 1. Enable Developer Tools: Open WPS Spreadsheet, navigate to the 'Developer' tab, and ensure macro support is enabled.
- 2. Insert your VBA Code: Click 'VBA Editor' to open the script environment and paste your baseline comparison macro.
- 3. Save and Execute: Save your file as a Macro-Enabled Workbook (.xlsm) and run the script to highlight genuine value changes instantly.

Frequently Asked Questions
Why does the Worksheet_Change macro highlight cells when nothing changed?
The Worksheet_Change event is triggered simply by a cell exiting edit mode. It does not store the cell's previous value, meaning it cannot verify if the new input is different from the original data unless you explicitly provide a reference.
How do I clear previous row highlights when a new weekly cycle starts?
You can manually select your data, go to the 'Home' tab, click the 'Fill Color' tool, and choose 'No Fill'. If using VBA, you can add a line like 'ActiveSheet.UsedRange.Interior.ColorIndex = xlNone' at the beginning of your script.
What happens if rows are inserted or deleted during the week?
If rows are inserted or deleted, direct cell-to-cell comparison (like A2 vs A2) will fail. You must use a unique identifier (e.g., a Product ID) and lookup functions (like VLOOKUP or MATCH) in your VBA code or Conditional Formatting to ensure you are comparing the same items.
Can I store the previous value without making a whole new reference sheet?
Yes, but it is complex. You can capture a cell's original value using the 'Worksheet_SelectionChange' event and store it in a public variable before the edit happens, then compare it during the 'Worksheet_Change' event. However, this is prone to errors during bulk edits or copy-pasting, making a reference sheet the more robust solution.




