HomeGoogle DocsSpreadsheetHighlight Rows When Value Changes in Google Sheets

Highlight Rows When Value Changes in Google Sheets

When you have a dataset sorted by categories in Google Sheets, you might want to highlight rows when values change in the category column. This means highlighting either the first or the last row of each category.

This is useful when specific information, such as a subtotal, is found in the last or first row of each category.

To highlight the first row, you’ll need one formula, and for the last row, another formula.

The conditional formatting settings are the same, except for the formula. Let’s dive into the formulas and how to apply the highlight rules.

Quick Answer: Highlight Rows When Value Changes

Use these formulas in conditional formatting:

Highlight last row:

=$B2<>$B3

Highlight first row:

=AND($B2<>"", $B1<>$B2)

Example 1: Highlight the Last Row of Each Category

The sample data consists of student names in column A, divisions in column B, and their marks in column C. The data is sorted by division, and the last row of each division contains the division average.

Highlighting the last row of each category in Google Sheets using conditional formatting

As a side note, I’ve used the following custom function in cell D2 to get the division average. You can import this function and similar aggregation functions from my guide: AT_EACH_CHANGE Named Functions in Google Sheets.

=IFNA(AVG_AT_EACH_CHANGE(B2:B, C2:C, -1))

Note: The custom function used here is optional. The highlighting formulas work independently without it.

To highlight the rows where the value changes in the division column, use the following conditional format rule:

=$B2<>$B3

Example 2: Highlight the First Row of Each Category

In this scenario, the average of each division is displayed in the first row of each division. The following custom function achieves that:

=IFNA(AVG_AT_EACH_CHANGE(B2:B, C2:C, 1))

To highlight the first row of each division, use the following conditional format rule:

=AND($B2<>"", $B1<>$B2)
Highlighting the first row of each category in Google Sheets using conditional formatting

You might think that this highlighting can be achieved by simply matching non-empty cells in column D. However, my formula highlights the rows based on changes in column B, not just non-empty cells. I’m focusing on this approach because you may or may not have a subtotal column. The goal is to identify the rows where the group changes in your table. With that clarified, let’s move on to the steps for applying the above rules to highlight these rows.

How to Apply Conditional Formatting for Value Changes

You can choose one of the rules above based on your requirements. Copy that rule, then follow the steps below:

  1. Select the range A2:D10 (or the range you want to highlight), avoiding the header row if there is one. In my case, A1:D1 contains the header, so I omitted that.
  2. Click Format > Conditional Formatting.
  3. In the sidebar panel, select “Custom formula is” under the “Format Rules.”
  4. Paste the copied formula in the provided field. If your range is not A2:D10, modify the formula accordingly. For example, if your range is A10:Z100 and the category column is A, the formulas should be:
    • For the last row: =$A10<>$A11
    • For the first row: =AND($A10<>"", $A10<>$A9)
  5. Select a highlighting style under “Formatting style.”
  6. Click Done.
Applying a custom conditional formatting formula to highlight rows when category values change in Google Sheets

This way, you can highlight rows based on value changes in a column in Google Sheets.

Common Mistakes When Highlighting Value Changes

  • Forgetting absolute references ($B2)
  • Applying formula to wrong range
  • Using incorrect row references
  • Not sorting data before applying rules

Conclusion

Highlighting rows when values change in Google Sheets is a simple yet powerful way to visually separate grouped data. Whether you want to highlight the first or last row of each category, using custom conditional formatting formulas gives you full control without requiring helper columns.

These techniques are especially useful in reports, grouped datasets, and dashboards where identifying category boundaries is important.

This tutorial is part of The Ultimate Guide to Conditional Formatting in Google Sheets, which covers a wide range of techniques, examples, and advanced use cases for working with data more effectively.

Resources

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

How to Build a Road Trip Fuel Cost Splitter Formula in Google Sheets

Need a fair formula to split fuel costs among travelers on a long road...

Road Trip Fuel Cost Splitter in Google Sheets (Free Template)

When you go on a long road trip with friends, splitting fuel expenses fairly...

Savings Tracker Template in Google Sheets (Free Download)

Managing multiple savings goals can become difficult without a proper system to track your...

4 COMMENTS

  1. Hi Prashanth,

    I’m trying to adapt your formula to highlight changes in any column A through to and including column N but I just can’t get this correct, can you advise pls?

  2. Thank you.

    This works great. Is it possible to extend this, so not just changes in 1 column e.g. column B but in a range of columns?

    Thanks again.

    • Hi, John,

      You can achieve that by combining the cells in corresponding columns.

      Assume you want to highlight rows when value changes in two columns and those columns are column B and C.

      Then you can go ahead with the below formula.

      When values in two columns change, highlight the entire row.

      Best,

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.