Formatting Issues

How to Alternate Row Colors by Group ID with Conditional Formatting

Maira MehtabMaira Mehtab Nov 10, 2026 870 views

Question details

The user wants to visually group records by applying alternate row colors based on a specific Team ID, ensuring that all rows sharing the same ID have the same background color.

Alternate Row Colors by Team ID Using Conditional Formatting
Product
Spreadsheet
Device & OS
not provided
Scenario
Formatting a large dataset to make groups of related records visually distinct from one another using dynamic color banding.
Observed behavior
The goal is to have the row background color automatically change only when the value in the Team ID column changes.
Before you start

Ensure your dataset is sorted by the Team ID column so that all identical IDs are grouped together before applying the conditional formatting rules.

Solution 1Recommended

Use XMATCH and UNIQUE Functions (Modern Spreadsheets)

This is the most efficient method for newer spreadsheet versions, dynamically applying formatting based on the occurrence of unique IDs.

This formula checks the position of the current row's ID against a unique list of all IDs in the specified range. By extending the range (e.g., to row 1000), you ensure the formatting applies as you add new data.

1
Select the Data Range

Highlight the entire dataset where you want the formatting applied, for example, cells A3:G1000.

2
Open Conditional Formatting

Navigate to the 'Home' tab and click on 'Conditional Formatting', then select 'New Rule'.

3
Input the Formula

Choose the option to use a formula to determine which cells to format. Enter the following formula: =MOD(XMATCH($B3,UNIQUE(TOCOL($B$3:$B$1000,1))),2)=1 (assuming column B contains your Team IDs and your data starts at row 3).

4
Set the Formatting Style

Click 'Format', go to the 'Fill' tab, choose your desired background color, and click 'OK' to apply the rule.

Use XMATCH and UNIQUE Functions (Modern Spreadsheets)
Dynamic Updates: If you convert your data range into a Table, the conditional formatting rule will automatically expand as you add new team records to the bottom.
Organize Data Seamlessly

Visually Group Your Data with WPS Spreadsheet

WPS Spreadsheet provides robust conditional formatting tools that fully support complex array formulas, helping you organize and visualize your grouped data effortlessly without any lag.

  1. 1. Open Your Dataset: Launch WPS Spreadsheet and open the document containing your team data.
  2. 2. Access Conditional Formatting: Highlight your data range, click the 'Home' tab, and select 'Conditional Formatting'.
  3. 3. Apply Your Rule: Click 'New Rule', paste your grouping formula, and customize your row colors to instantly transform your table.
Fully compatible with Microsoft Excel (.xlsx) formulas and formattingAdvanced conditional formatting capabilities for dynamic data analysisFree and lightweight alternative to heavy office suitesFamiliar user interface with zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

How can I apply a second color instead of leaving alternating rows white?

To alternate between two specific custom colors, create a second conditional formatting rule for the same data range. Use the exact same formula but change the end from =1 to =0, and choose your second color in the formatting options.

Why are my rows not grouping together properly?

These conditional formatting formulas assign colors based on the sequential occurrence of unique values. If your data is not sorted by the Team ID column, identical IDs might be separated, which breaks the visual grouping block. Always sort your data by the grouping column first.

Will this formatting automatically apply if I add a new team to the bottom of the list?

Yes, provided your formula references a range larger than your current dataset (e.g., $B$1000). Alternatively, if you format your dataset as a Table, the conditional formatting rules will automatically extend as new rows are added.