HomeGoogle DocsSpreadsheetHighlight Visible Duplicates in Google Sheets

Highlight Visible Duplicates in Google Sheets

Published on

We can generally apply three types of highlighting rules to duplicates. Without understanding that, there is no meaning in proceeding with how to highlight visible duplicates in Google Sheets.

What are those three types of format rules?

Duplicates mean multiple occurrences of values. So there will be a first occurrence, a second occurrence, a third occurrence, and so on.

When you find a duplicate that repeats thrice, what you may want to do usually with conditional formatting?

Do you prefer to highlight all three occurrences, the last two occurrences, or the first two occurrences?

See the image below, where I have applied different conditional formatting rules.

You can see the type 1 rule ( I named it so for this tutorial purposes) in column A, type 2 in column C, and type 3 in column E.

3 types of duplicate highlighting in Google Sheets

I have explained these conditional formatting types in my tutorial – Highlight Duplicates in Single, Multiple Columns, and All Cells in Google Sheets.

I hope you have gone through that. If not, read that tutorial first, though it’s not a must here.

Visible Duplicates in Google Docs Sheets – What is it?

Suppose cells A1 and A2 contain the number 100, so duplicate values. I am hiding or filtering out row # 1 (cell A1).

After that, there is only one occurrence of the value 100 (in cell A2). So it’s not a duplicate considering visible duplicates.

In the following examples, you can learn how to exclude the values in hidden/filtered-out rows while finding duplicates and highlighting them.

How to Highlight Visible Duplicates in Docs Sheets

We must use a helper column in Docs Sheets to exclude hidden rows in conditional or criterion-driven formulas. So let me begin with that.

In the first example, we will use type 3 duplicate highlighting, i.e., highlighting all the occurrences of duplicates.

Highlight All the Occurrences of Visible Duplicates in Google Sheets

Here is the screenshot. In this, see the formula in cell B1, which I have dragged down until cell B9.

=subtotal(103,A1)
skip hidden rows in highlighting

As an alternative, empty B1:B9 and insert the following formula in cell B1, where the MAP expands the SUBTOTAL.

=map(A1:A9,lambda(row,subtotal(103,row)))

What does this Subtotal formula do?

When a row is hidden, the value in that cell, I mean the Subtotal formula applied cell, becomes 0 (zero)!

You May Like:- Subtotal function with conditions in Excel and Google Sheets.

To test this Subtotal feature, let me use the below formula in cell D5.

=B3

The Subtotal formula returns 1 in cell D5. See the value in cell D5 changes to 0 when I hide row # 3.

helper column using subtotal in highlighting

I am going to make use of this feature of the Subtotal formula to highlight only the visible duplicates in Google Sheets.

Here is the custom formula to conditional format visible duplicates in Google Spreadsheet.

=countifs($A$1:$A25,$A1,$B$1:$B25,$B1)>1

I am applying this rule up to row # 25. So copy the Subtotal formula in cell B1 up to this row.

If you are using the Map formula, replace A1:A9 with A1:A25.

To apply this formula in conditional formatting, do as follows.

  1. Go to the menu Format > Conditional Formatting.
  2. There set the “Apply to range” to A1:A25.
  3. Select “Custom Formula” under “Format rules” and enter the above formula.
highlight visible duplicates in Google Sheets - All occurrence

If you refer to the above screenshot (this screenshot contains three images, I am talking about the leftmost one), you can see three occurrences of the value Orange.

When I hide row # 7, it appears twice. So again a duplicate.

But when I hide rows 6 and 7, only one Orange is visible.

Even though it has duplicates in the hidden rows, the highlighting won’t get applied.

The reason, there are no visible duplicates of this value.

Highlight All Visible Duplicates Leaving the First Occurrence

In the beginning, I mentioned the three types of formatting.

Here is the second one, in that, i.e., highlights all duplicates leaving the first occurrence.

Every setting is as per the above example, like using the Subtotal/Map formula and applying the conditional formatting rule.

But the custom conditional formatting formula is different.

Here is the formula to use in this case.

=countifs($A$1:$A1,A1,$B$1:$B1,B1)>1

The above is the type 2 formula to highlight visible duplicates in Google Sheets.

See the following screenshot to understand how this differs from the previous rule.

Conditional format all visible duplicates leaving the first occurrence

Highlight All Visible Duplicates Leaving the Last Occurrence

It is similar to the just above highlighting rule.

Here also, we are ignoring the values in the hidden rows with the help of the helper column and the Subtotal Formula.

Here, the only difference with the just above formatting rule is it highlights all the duplicates leaving the last occurrence (type 1).

=countifs(A1:A25,A1,B1:B25,B1)>1

Once again, I am going to make use of the screen capture to make you understand this.

highlight visible duplicates leaving the last occurrence

That’s all. You can follow the above three types to highlight visible duplicates in Google Sheets. Enjoy!

More Conditional Formatting Tips:

  1. Date Related Conditional Formatting Rules in Google Sheets.
  2. Find All the Cells Having Conditional Formatting in Google Sheets.
  3. AND, OR, or NOT in Conditional Formatting in Google Sheets.
  4. Conditional Format Based on Group of Data in Google Sheets.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

More like this

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

3 COMMENTS

  1. Hi, this is super, thanks Prashanth, got it to work great for a vertical range, i.e. same scenario as above. However, I’m also trying to get it to work on a separate sheet for a horizontal range, but can’t get it to work…I’ve tested & confirmed that the subtotal formula is not working for a horizontal instead of vertical scenario.

    For example, my list is going across a single row, with the subtotal formulas set up on the row below that, but when I hide one of the columns, the subtotal formula in the hidden column still calculates to 1, instead of 0. Any ideas on how to make it work? Is there a different formula than subtotal that works for horizontal ranges instead of just vertical?

    Thank you!

    • Hi, Grad Art,

      For horizontal range, as you have tested, we can’t follow this method. I thought we can use the CELL function to find the width as below and use that in conditional formatting.

      =cell("width",E1)

      My assumption was it would return ‘0’ as the output when the Column E is hidden. But the column width remains the same. So I don’t have any option/workaround to offer.

      Best,

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.