How to Apply Alternate Conditional Formatting for Matching Account Groups in Excel
Question details
The user needs a method to apply alternating background highlight colors to consecutive rows that share the same Account Number.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Working with large datasets where it is visually necessary to distinguish grouped records, such as matching account numbers or order IDs, to improve readability.
- Observed behavior
- The user wants the groups of rows sharing an identical identifier to automatically alternate in color, remaining structurally sound when the data is sorted.
Ensure your dataset is sorted by the Account Number column so that matching records are grouped consecutively before applying any formulas.
Use a Helper Column with IF and NOT Formulas
This is the most reliable method across all spreadsheet versions. It utilizes a helper column to toggle TRUE and FALSE values between different account groups, which conditional formatting then uses to apply colors.
By setting up a helper column, we can force a value to switch back and forth every time the account number changes. Once the logic is in place, a simple formatting rule colors the rows.
Assuming your Account Numbers are in column B and your data starts on row 2, pick an empty column for your helper (e.g., column G). In cell G1, type 'FALSE'.
In cell G2, enter the formula =IF(B2=B1,G1,NOT(G1)). This checks if the current account number matches the one above it; if it does, it keeps the same TRUE/FALSE value. If not, it flips it. Drag this formula down to the end of your data.
Select your entire data range. Navigate to Home > Conditional Formatting > New Rule. Choose 'Use a formula to determine which cells to format'.
Enter the formula =$G2=TRUE (ensure the column is absolute with a '$' and the row is relative). Click 'Format', choose your preferred fill color, and click OK.
To keep your worksheet clean, right-click the header of your helper column (Column G) and select 'Hide'.

Use UNIQUE and FILTER Functions (Microsoft 365 Only)
If you are using Microsoft 365, you can use dynamic array functions to create a virtual helper list for formatting, eliminating the need for a line-by-line helper column.
Easily Highlight Data Groups in WPS Spreadsheet
WPS Spreadsheet fully supports advanced conditional formatting and logic formulas like IF and VLOOKUP, making it incredibly easy to visually format matching account groups.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your dataset containing the account numbers.
- 2. Create your helper column: Pick a blank column, enter FALSE in the top row, and use the =IF(B2=B1,G1,NOT(G1)) formula to flag alternating groups.
- 3. Access Conditional Formatting: Highlight your data, navigate to the 'Home' tab on the top ribbon, and click 'Conditional Formatting'.
- 4. Apply your custom rule: Select 'New Rule', choose 'Use a formula', enter =$G2=TRUE, set your desired highlight color, and save.

Frequently Asked Questions
Will the alternating colors remain correct if I filter the data?
Standard filtering might disrupt the alternating pattern if specific rows within a group are hidden. To maintain alternating colors while filtering, you may need a more complex formula utilizing the SUBTOTAL or AGGREGATE functions to ignore hidden rows, rather than a simple IF check.
Why is my conditional formatting rule highlighting the wrong rows entirely?
This usually happens due to incorrect absolute and relative referencing. Ensure that you are using an absolute column reference and a relative row reference (like $G2) in your conditional formatting formula. Additionally, verify that your rule applies to the correct range starting from row 2.
Can I use more than two colors for alternating groups?
Yes. To cycle through three or more colors, modify the helper column to increment a number using the MOD function (e.g., =IF(B2=B1, G1, MOD(G1+1, 3))). Then, set up three separate conditional formatting rules to look for the values 0, 1, and 2, assigning a different color to each.




