The simplest Google Sheets formula to find duplicate values is =COUNTIF(range, cell)>1 used in a helper column, or =UNIQUE(range) to list only unique entries. For highlighting duplicates, use conditional formatting with =COUNTIF(A:A, A1)>1.
Why Duplicate Detection Matters
Duplicate values in a spreadsheet can come from merged data imports, manual entry errors, or repeated submissions in forms. They distort counts, averages, and lookup results, and can cause mailing lists to send the same email twice. Google Sheets offers several ways to identify, highlight, or remove duplicates, each suited to a different task. The right approach depends on whether you need to see them, count them, or eliminate them permanently.
Using COUNTIF to Flag Duplicates
The COUNTIF function counts how many times a value appears in a range. When you compare that count to 1, you get a TRUE/FALSE result that marks duplicates.
Assume your data is in column A, rows 2 to 20, with headers in row 1. In cell B2, enter:
=COUNTIF($A$2:$A$20, A2)>1
Drag the formula down to B20. Any cell that shows TRUE is a duplicate (appears more than once). If you want to see the actual count instead of TRUE/FALSE, use:
=COUNTIF($A$2:$A$20, A2)
This returns 1 for unique values, 2 for the first duplicate, 3 for the second, and so on. The absolute references ($A$2:$A$20) keep the range fixed as you copy the formula down.
Highlighting Duplicates with Conditional Formatting
Conditional formatting is the fastest way to visually spot duplicates without adding extra columns. Select the range you want to check (e.g., A2:A20), then go to Format > Conditional formatting. Under “Format rules,” choose “Custom formula is” and enter:
=COUNTIF($A$2:$A$20, A2)>1
Set a fill color and click Done. The formula uses the top-left cell of the selected range (A2) as the reference, and Sheets adjusts it for each row. This highlights every occurrence of a value that appears more than once—not just the second and later ones. If you only want to highlight the second and subsequent duplicates (leaving the first instance unhighlighted), use:
=COUNTIF($A$2:A2, A2)>1
Here the range expands as it goes down, so the first occurrence has a count of 1 and stays unhighlighted.
Removing Duplicates with the Built-in Tool
If you want to delete duplicates entirely, use the native menu: Data > Data cleanup > Remove duplicates. Select the range (or let Sheets detect it), check “Data has header row” if applicable, and choose which columns to compare. Click “Remove duplicates.” Sheets will tell you how many rows were removed and how many remain. This permanently deletes rows, so save a copy first or use Ctrl+Z (or Cmd+Z on Mac) immediately if you change your mind.
For more control, you can use UNIQUE to create a separate list of distinct values. In a new column, enter:
=UNIQUE(A2:A20)
This spills the unique values into the cells below, leaving your original data untouched. It’s a safe way to get a clean list without deleting anything.
Counting Duplicates Across Multiple Columns
Sometimes duplicates are defined by a combination of columns, like first name and last name. To find rows where both columns match an earlier row, use COUNTIFS instead of COUNTIF.
With names in A2:A20 and last names in B2:B20, put this in C2:
=COUNTIFS($A$2:$A$20, A2, $B$2:$B$20, B2)>1
This returns TRUE only when the same first and last name pair appears more than once. For conditional formatting across two columns, select both columns (e.g., A2:B20) and use the custom formula:
=COUNTIFS($A$2:$A$20, $A2, $B$2:$B$20, $B2)>1
Note the mixed references: the column letters are absolute ($A, $B) but the row numbers are relative (2). This ensures the formula checks the entire range while applying to each row correctly.
Common Problems and Misconceptions
One frequent issue is that COUNTIF treats text and numbers differently. A value like “123” as text and the number 123 are not considered duplicates. To avoid this, ensure your data is consistently formatted. Another misconception is that conditional formatting highlights only the second occurrence—by default it highlights all, which is often what users actually want.
Another problem: when using COUNTIF with an entire column (e.g., A:A), it will count empty cells as duplicates if you have blank rows. To exclude blanks, use:
=IF(A2="", "", COUNTIF($A$2:$A$20, A2)>1)
This leaves blank cells empty instead of marking them as duplicates.
Comparing with Excel
Google Sheets and Excel have similar functions, but the menus differ. In Excel for Microsoft 365, you would use the same COUNTIF formula, but conditional formatting is found under Home > Conditional Formatting > New Rule > Use a formula. Excel also has a “Remove Duplicates” button under Data > Remove Duplicates. However, Google Sheets’ UNIQUE function is not available in older Excel versions; Excel uses UNIQUE only in Excel 365 and Excel 2021. For older Excel, you’d use Advanced Filter or a pivot table.
Performance and Large Datasets
If you have tens of thousands of rows, array formulas like COUNTIF can slow down your sheet because they recalculate every time you edit. For large data, consider using the built-in Remove duplicates tool first, or use QUERY to group and count. For example, to list each value and its count:
=QUERY(A2:A20, "select A, count(A) where A is not null group by A label count(A) 'Count'")
This returns a two-column table of unique values and their frequencies. It’s efficient and doesn’t require dragging formulas.
Frequently Asked Questions
How do I find duplicates in two columns in Google Sheets?
Use COUNTIFS with both columns as criteria. For example, =COUNTIFS($A$2:$A$20, A2, $B$2:$B$20, B2)>1 in a helper column, or apply it in conditional formatting as described above.
Can I highlight duplicates in Google Sheets without a formula?
Yes, you can use the built-in conditional formatting preset: select your range, go to Format > Conditional formatting, then under “Format rules” choose “Is equal to” and type the value you want to highlight. However, this only highlights a specific value, not all duplicates automatically. For all duplicates, you need the custom formula.
Why is my COUNTIF formula returning 0 for obvious duplicates?
Check for leading/trailing spaces or non-printing characters. Use =TRIM(A2) to clean data, or use =ARRAYFORMULA(TRIM(A2:A20)) to trim a whole range. Also ensure the range in COUNTIF matches the data type (text vs. number).
Does Google Sheets have a “Remove Duplicates” button?
Yes, it’s under Data > Data cleanup > Remove duplicates. You can choose which columns to compare and whether your data has a header row. It permanently deletes duplicate rows, so save a backup first.
How do I only keep the first occurrence and delete the rest?
Use conditional formatting with the expanding range formula =COUNTIF($A$2:A2, A2)>1 to highlight all but the first occurrence. Then filter by the highlight color (right-click > Filter by color) and delete those rows. Alternatively, sort by the column and manually remove repeats, but the color filter method is safer.
Can I use UNIQUE to remove duplicates from a column?
Yes, =UNIQUE(A2:A20) returns a list of unique values in a new location. To replace the original data, copy the unique list and paste it over the original column using “Paste special > Values only.” This does not affect other columns, so be careful if your rows have other data.
Related
- Generate 4 Random Numbers in Python: Easy Steps
- Free Time Tracking Excel Template: How to Build One
- Free Student Attendance Template Excel: Get One
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Java Code to Split String: Methods & ExamplesThe simplest way to split a string in Java is to call the split() method on the string…
- Excel Merge Cells: How to Combine Cells in ExcelYes, Excel can merge cells. To merge cells in Microsoft Excel, select the cells you want to combine,…
- Excel Table Saw: Models, Safety, and Buying AdviceAn Excel table saw is a woodworking saw sold under the Excel name; it is not a Microsoft…
- Shortcut Keys for Typing: The Essential ListThe most useful shortcut keys for typing are Ctrl+C (copy), Ctrl+X (cut), Ctrl+V (paste), Ctrl+Z (undo), and Ctrl+A…
- Correlation Table in Excel: Create and Read OneIn Excel for Microsoft 365 on Windows, create a correlation table by choosing Data > Data Analysis >…
- Multiply Hours by Money in Excel: A Practical GuideTo calculate pay from decimal hours, put the hours in B2 and the hourly rate in C2, then…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.