Going Stellar

Home/Google Sheets reference

Google Sheets recipe

How to remove duplicates in Google Sheets with formulas

=UNIQUE(A2:A6) returns the list without repeated values and leaves the original column untouched. Because it compares exact text, clean the column first with TRIM and LOWER inside ARRAYFORMULA when near-duplicates should merge too.

Steps

  1. Pick an empty cell next to the data, such as D1, so the result has room to spill downward.
  2. Enter =UNIQUE(A2:A6). Each distinct value appears once, in order of first appearance.
  3. Check the count with =COUNTUNIQUE(A2:A6) and compare it to the number of rows UNIQUE returned.
  4. If near-duplicates survive, wrap the column in ARRAYFORMULA(TRIM(...)) and, when case should not matter, in LOWER as well.
  5. Wrap the whole thing in SORT to get an alphabetical list.
  6. To see which values occur only once, add FALSE and TRUE as the second and third arguments of UNIQUE.

Examples

The examples use this table, starting in A1:

Item
tea
Coffee
tea
Coffee
Tea
=UNIQUE(A2:A6)

Result:

tea
Coffee
Coffee
Tea

One row per distinct value, in order of first appearance. The second tea disappears, but Tea and "Coffee " survive.

Run in a Google Sheet (English US locale) on .

=COUNTUNIQUE(A2:A6)

Result: 4

How many distinct values the list has, without listing them.

Run in a Google Sheet (English US locale) on .

=UNIQUE(ARRAYFORMULA(TRIM(A2:A6)))

Result:

tea
Coffee
Tea

TRIM first, so "Coffee " and Coffee become one value. Tea is still separate.

Run in a Google Sheet (English US locale) on .

=SORT(UNIQUE(ARRAYFORMULA(LOWER(TRIM(A2:A6)))))

Result:

coffee
tea

Full clean-up: trim, lowercase, remove repeats, sort A to Z.

Run in a Google Sheet (English US locale) on .

=UNIQUE(A2:A6, FALSE, TRUE)

Result:

Coffee
Coffee
Tea

Third argument TRUE keeps only values that occur exactly once. Both lowercase tea copies drop out, while Tea stays.

Run in a Google Sheet (English US locale) on .

Common errors

  • UNIQUE and COUNTUNIQUE respect case, so tea and Tea count as two values. Lowercase the column first when they should merge.
  • A trailing space makes a value distinct: "a" and "a " count as 2. TRIM removes it.
  • TRIM placed directly inside UNIQUE returns #VALUE!. Put it inside ARRAYFORMULA, as in the third example.

Compared with Excel

UNIQUE and SORT also exist in Excel 365 and Excel 2021. COUNTUNIQUE does not exist in Excel, and Excel does not need ARRAYFORMULA because it spills arrays by default.

Functions used

Sources

  1. UNIQUE (Docs Editors Help)
  2. COUNTUNIQUE (Docs Editors Help)
  3. SORT (Docs Editors Help)
  4. TRIM (Docs Editors Help)

Markdown version · All functions