Highlight Conditional Duplicates in Google Sheets

Published on

When working with spreadsheets, it’s common to highlight duplicates in Google Sheets to catch repeated entries, errors, or data quality issues. Normally, duplicates are identified when the same value appears more than once in a column or row.

But what if you only want to highlight duplicates based on specific conditions? For example:

  • When certain products are purchased together.
  • When an item is repeated more times than allowed.
  • When duplicates should only be flagged under business rules, not just raw repetition.

That’s where conditional duplicate highlighting comes in.

In this guide, you’ll learn step by step how to highlight duplicates in Google Sheets with conditions using custom formulas and conditional formatting. This goes beyond the basic “highlight duplicates” feature and gives you full control over which entries should actually be flagged.

Example of Conditional Duplicate Highlighting in Google Sheets

Let’s say column A contains the name of the person ordering books, and column B lists the books they ordered.

We have limited stock of Book A and Book B, so a person can order either one, but not both.

Sample Data:

Sample Google Sheets data showing conditional duplicates highlighted in different colors
  • Jesse ordered both Book A and Book B → This should be flagged.
  • Mike ordered Book C twice → This can also be flagged if we want to catch repeated entries.

This is where conditional duplicate highlighting shines.

How to Highlight Duplicates with Conditions in Google Sheets

Follow these steps:

  1. Select your rangeA2:B
  2. Go to Format > Conditional formatting
  3. Under Format rules, choose Custom formula is
  4. Enter this first formula:
=COUNTIFS($A$2:A2, $A2, $B$2:B2, $B2)>1

👉 This rule highlights regular duplicates.
Set the formatting style to “Light Orange”.

  1. Now, click Add another rule and enter this formula:
=LET(
   range_2, ARRAYFORMULA(REGEXREPLACE($B$2:B2, "Book A|Book B", "x")), 
   COUNTIFS($A$2:A2, $A2, range_2, CHOOSEROWS(range_2, -1))>1
)

👉 This is the conditional rule that actually highlights conditional duplicate entries.
Set the formatting style to Yellow.

Google Sheets conditional formatting sidebar showing two rules applied for highlighting duplicates

Why You Need Two Rules for Duplicate Highlighting

The second formula conditionally flags duplicates. On its own, though, it would also highlight regular duplicates. That’s why we add the first formula — it applies a different color, making it easy to tell them apart.

Formula Breakdown for Conditional Duplicate Highlighting

Formula 1: Highlight Regular Duplicates

=COUNTIFS($A$2:A2, $A2, $B$2:B2, $B2)>1

This checks if the same person ($A$2:A2) ordered the same book ($B$2:B2) more than once.

Formula 2: Highlight Conditional Duplicates

=LET(
   range_2, ARRAYFORMULA(REGEXREPLACE($B$2:B2, "Book A|Book B", "x")), 
   COUNTIFS($A$2:A2, $A2, range_2, CHOOSEROWS(range_2, -1))>1
)
  • REGEXREPLACE($B$2:B2, "Book A|Book B", "x") → replaces both Book A and Book B with a placeholder "x".
  • ARRAYFORMULA(...) → applies this replacement across the entire column range.
  • LET(range_2, ...) → stores the modified list as range_2.
  • CHOOSEROWS(range_2, -1) → selects the current row’s value from that modified list.
  • COUNTIFS($A$2:A2, $A2, range_2, CHOOSEROWS(...))>1 → checks if the same person has already ordered an "x" (meaning Book A or Book B).

👉 Flags conditional duplicates (e.g., Book A + Book B = treated as two "x" orders).

Extending the Formula for More Conditions

You can add more conditions by updating the REGEXREPLACE pattern:

"Book A|Book B|Book W"

👉 To make it case-insensitive and exact match only, use:

"(?i)^(Book A|Book B|Book W)$"

Final Thoughts

Highlighting conditional duplicates in Google Sheets gives you more flexibility than the standard duplicate highlighting feature. By combining COUNTIFS, REGEXREPLACE, and conditional formatting, you can enforce business rules — like limiting certain products or flagging over-purchases — directly in your sheet.

Once you understand the logic, you can adapt these formulas to match your own conditions, whether that’s products, dates, or any other business rule.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.