Highlight Groups with Alternating Colors in Excel

Highlighting groups with alternating colors can improve readability in Excel. It has another advantage: you can filter every alternate group by applying a filter and selecting ‘Filter by Color’.

Alternating row color is a common practice in spreadsheets. However, sometimes we may want to take it one step further, such as highlighting groups with alternating colors. It’s easy to do without using multiple formulas or helper columns (cells) in Excel.

We have a table with a few electronic items, sorted item-wise, in column A, along with their units and quantities. The items are Laptop, Tablet, Smartphone, Smartwatch, and Headphones.

Conditional Formatting in Excel to Highlight Groups with Alternating Colors

How do we highlight the rows containing “Laptop”, “Smartphone”, and “Headphones”—that means every alternating group—in Excel?

New Rule to Highlight Groups with Alternating Colors in Excel

Here is the formula that we will apply within Conditional Formatting to highlight every alternating group with a color:

=ISODD(MATCH($A2, UNIQUE($A$2:$A$11), 0))

Where $A2 represents the very first cell in the column that determines the group, and $A$2:$A$11 is the range of the group.

Before we apply this within Excel’s conditional formatting as a ‘New Rule’, let’s learn what this formula does.

Formula Breakdown

You can skip this part as it is included only for educational purposes.

UNIQUE($A$2:$A$11) – This function returns the unique values from the specified range, removing duplicates:

Laptop
Tablet
Smartphone
Smartwatch
Headphones

MATCH($A2, …, 0) – This function matches the first item in the group among the unique values above and returns its position. For example, it returns 1 for “Laptop” because it is the first item in the unique list.

ISODD(…) – This function returns TRUE if the position is an odd number.

Here is the crux of highlighting groups with alternating colors in Excel. We will apply this formula as a ‘New Rule’ within Conditional Formatting for the range A2:C11. If any cell reference is relative in the formula, it will increment in each row.

In our formula, the search key in the MATCH function is relative by row, which is $A2. It will become $A3, $A4, $A5, …, $A11.

This means the MATCH function matches all values in the group with the unique group values. So for “Laptop,” it will return 1 (TRUE), for “Smartphone,” it will return 3 (TRUE), and for “Headphones,” it will return 5 (TRUE), and those rows will be highlighted.

Highlighting Groups with Alternating Colors in Excel

First, copy the above formula and follow the instructions below:

  1. Select the range A2:C11.
  2. In the Home tab, within the Styles group, click on Conditional Formatting > New Rule.
  3. Select “Use a formula to determine which cells to format.”
  4. In the field under “Format values where this formula is true,” paste the copied formula.
    Applying New Rule for highlighting alternating groups with colors
  5. Click the “Format” button to open the Format Cells dialog box.
  6. Select a Fill Color you want.
  7. Click OK to close the Format Cells dialog box.
  8. Click OK again to close the New Formatting Rule dialog box.

This will highlight every other group with the chosen color, leaving an unfilled group between each highlighted group. If you want to highlight those groups with a different color, do as follows:

Follow the above steps 1 to 8 and use the following formula in the formula field:

=ISEVEN(MATCH($A2, UNIQUE($A$2:$A$11), 0))

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.

Top N Products and Top N Sellers in Google Sheets (Top N of Top N)

If you’ve ever wanted to compare which sellers contribute the most to your top-selling...

Use XLOOKUP in a Structured Table in Google Sheets (Single and Multiple Conditions)

This tutorial is for users who want to apply XLOOKUP inside a structured table...

Reset SCAN by Another Column in Google Sheets and Excel

Resetting SCAN function results based on values in another column is a topic of...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

More like this

Sort Each Row Individually in Excel Using a LAMBDA Formula

Sorting rows in Excel typically refers to rearranging entire datasets based on values in...

Sort by Field Labels Using the SORT and XMATCH Combo in Excel

Want to sort your Excel data by column names instead of column positions? Learn...

Dynamic Way to Insert Blank Rows in a Table in Excel

Do you want to easily insert n number of blank rows in a table...

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.