How to Alternate Fill Colors for Groups of Rows in Spreadsheets
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.

- 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.
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.
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.
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.
Navigate to the 'Home' tab on the top ribbon, click on 'Conditional Formatting', and select 'New Rule' from the dropdown list.
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.
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.

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. Open your dataset in WPS Spreadsheet: Launch WPS Office, open your spreadsheet file, and sort your data by the target grouping column.
- 2. Highlight the target range: Select the data rows where you want to apply the grouped coloring, starting directly below the header.
- 3. Apply Conditional Formatting: Go to 'Home' > 'Conditional Formatting' > 'New Rule', input the ISODD and UNIQUE formula, configure your preferred fill color, and save.

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.




