Formatting Issues

How to Alternate Fill Colors for Groups of Rows in Spreadsheets

Ayan MasoodAyan Masood Nov 11, 2026 872 views

Question details

The user wants to apply alternating background colors to groups of consecutive rows that share the same value in a specific column, rather than alternating row by row.

How to Alternate Fill Colors for Groups of Rows with the Same Value
Product
Spreadsheets
Device & OS
not provided
Scenario
Formatting a report or dataset to visually separate distinct data groups, making the table much easier to read and analyze.
Observed behavior
Needs a conditional formatting formula that dynamically triggers a fill color change only when a new value appears in the specified grouping column.
Before you start

Ensure your dataset is sorted by the grouping column (e.g., Column B) so that all identical values are grouped in consecutive rows before applying the conditional formatting rule.

Solution 1Recommended

Use Conditional Formatting with ISODD, COUNTA, and UNIQUE

This formula-based rule dynamically calculates the number of unique items up to the current row and applies a fill color to alternating groups.

By combining the ISODD, COUNTA, and UNIQUE functions, the spreadsheet counts the distinct values in the grouping column. Every time a new group begins, the count increments. The ISODD function checks if this count is an odd number, applying the formatting only to alternate groups and creating a distinct banded effect.

1
Select your data range

Highlight the report rows you want to format, starting from row 2 (for example, A2:F100). Do not include the header row in your selection.

2
Open the Conditional Formatting menu

Navigate to the 'Home' tab on the top ribbon, click on 'Conditional Formatting', and select 'New Rule' from the dropdown list.

3
Enter the custom formula

Choose the option 'Use a formula to determine which cells to format'. In the formula box, enter: =ISODD(COUNTA(UNIQUE($B$2:$B2))). This assumes Column B contains your grouped values.

4
Set the fill color

Click the 'Format' button, go to the 'Fill' tab, and select a gray color (or any color of your choice). Click 'OK' twice to apply the rule.

Use Conditional Formatting with ISODD, COUNTA, and UNIQUE
Absolute and Relative References: Ensure the formula's cell references match your exact grouping column. The first cell ($B$2) must be an absolute reference, while the second part ($B2) must have a relative row number so it expands as the rule applies down the list.

Easily Format Data Groups with WPS Spreadsheet

WPS Spreadsheet fully supports advanced conditional formatting formulas, including dynamic arrays, allowing you to highlight data groups effortlessly. It is highly compatible with Excel formats and provides a smooth, intuitive data processing experience.

  1. 1. Open your dataset in WPS Spreadsheet: Launch WPS Office, open your spreadsheet file, and sort your data by the target grouping column.
  2. 2. Highlight the target range: Select the data rows where you want to apply the grouped coloring, starting directly below the header.
  3. 3. Apply Conditional Formatting: Go to 'Home' > 'Conditional Formatting' > 'New Rule', input the ISODD and UNIQUE formula, configure your preferred fill color, and save.
Fully compatible with Microsoft Excel's conditional formatting rules and dynamic array functions.Easily alternate row and group colors to dramatically improve large dataset readability.Lightweight, fast, and features a familiar user interface with no learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why is the alternating color changing on every row instead of by group?

This usually happens if your data is not sorted properly. The formula counts unique values sequentially down the column. If the same value is scattered throughout your list, the formula treats each new appearance as a new group. Ensure your data is sorted by the grouping column first.

Can I use this formula in older spreadsheet versions?

The UNIQUE function is a dynamic array function available in newer spreadsheet software. If you are using an older version, you will need to create a helper column using an IF formula to manually track value changes (e.g., =IF(B2=B1, C1, C1+1)), and then apply conditional formatting based on whether that helper column is odd or even.

How do I alternate between two specific colors instead of white and gray?

By default, the cells without conditional formatting will display the standard background color (usually no fill/white). To use two custom colors, apply your first standard background fill color to your entire dataset normally. Then, apply the conditional formatting rule to overlay the second color onto the alternate groups.