Highlight Rows When Value Changes in Google Sheets

Published on

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.

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

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))

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

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.

Applying Custom Formula Rules for Highlighting Value Change Rows

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

Applying Custom Formula Rules to Highlight Rows with Value Changes
  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.

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

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Lookup Previous Values Dynamically in Excel and Google Sheets

Sometimes, you may want to look up the previous values relative to the current...

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

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.