logo
search
Formatting Issues

How to Apply Alternate Conditional Formatting for Matching Account Groups in Excel

Huma Ashraf ChHuma Ashraf Ch Sep 27, 2026 871 views

Question details

The user needs a method to apply alternating background highlight colors to consecutive rows that share the same Account Number.

How to Apply Alternate Conditional Formatting for Matching Account Groups
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.
Before you start

Ensure your dataset is sorted by the Account Number column so that matching records are grouped consecutively before applying any formulas.

Solution 1Recommended

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.

1
Set up the initial helper cell

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'.

2
Enter the toggling formula

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.

3
Apply Conditional Formatting

Select your entire data range. Navigate to Home > Conditional Formatting > New Rule. Choose 'Use a formula to determine which cells to format'.

4
Set the rule and color

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.

5
Hide the helper column

To keep your worksheet clean, right-click the header of your helper column (Column G) and select 'Hide'.

Use a Helper Column with IF and NOT Formulas
Sorting Compatibility: Because the formula dynamically checks the row directly above it, the formatting will automatically recalculate and remain accurate even if you re-sort the data by Account Number later.

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. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your dataset containing the account numbers.
  2. 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. 3. Access Conditional Formatting: Highlight your data, navigate to the 'Home' tab on the top ribbon, and click 'Conditional Formatting'.
  4. 4. Apply your custom rule: Select 'New Rule', choose 'Use a formula', enter =$G2=TRUE, set your desired highlight color, and save.
Free and lightweight spreadsheet applicationFully compatible with Microsoft Excel formulas and .xlsx filesAdvanced Conditional Formatting rules natively supportedClean, tabbed interface for managing large datasets effortlessly
microsoft office alternative - wps office

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.