Dynamic Arrays

How to Remove Duplicates With the UNIQUE Function in Excel

Use the UNIQUE function to list each value once without changing your data. Covers one or several columns, values that appear once, blanks and stray spaces.

On this page
  1. The short answer
  2. UNIQUE or Remove Duplicates
  3. One column
  4. Several columns
  5. Values that appear only once
  6. Counting the distinct values
  7. Blank cells
  8. Hidden spaces
  9. Sorting the result
  10. Google Sheets
  11. Tips

The short answer

=UNIQUE(A2:A100) returns the distinct values in A2:A100, each shown once, in the order they first appear. The original list doesn’t change.

UNIQUE works in Excel for Microsoft 365, Excel 2021 and Excel for the web. In older versions, the formula shows #NAME?.

UNIQUE or Remove Duplicates

The Remove Duplicates button on the Data tab deletes repeated rows from your sheet. Once you save, those rows are gone unless you have a copy. UNIQUE builds a new list somewhere else and leaves the source alone.

Use UNIQUE when you want to keep the original data. Use Remove Duplicates when you actually want the repeated rows gone.

One column

Type the formula into an empty cell, such as D2:

=UNIQUE(A2:A100)

Excel fills D2 downward with each distinct value. The list can be shorter or longer than A2:A100, so leave the cells below D2 empty. If something sits in the way, the formula shows #SPILL!.

Several columns

When you pass more than one column, UNIQUE removes rows that repeat across all of them, not each column on its own:

=UNIQUE(A2:C100)

Two rows count as the same only if every column matches.

Values that appear only once

Set the third argument to TRUE to see only the values that appear exactly once. The second argument is the by_col setting, and leaving it empty keeps the default of comparing rows:

=UNIQUE(A2:A100,,TRUE)

Counting the distinct values

Wrap UNIQUE in ROWS to count how many distinct values there are:

=ROWS(UNIQUE(A2:A100))

Counting is a related task, and how to count unique values in excel covers more ways to do it. If the range has blank cells, the count includes one blank, so clean the blanks first, as shown below.

Blank cells

If the range contains blank cells, UNIQUE returns one blank among the values. To drop the blanks, filter them out first:

=UNIQUE(FILTER(A2:A100, A2:A100<>“”))

Hidden spaces

“Apple” and “Apple “ (with a trailing space) look the same on screen, but UNIQUE counts them as different values. The result then looks like it still has duplicates. Clean the text with TRIM inside the formula:

=UNIQUE(TRIM(A2:A100))

Sorting the result

UNIQUE returns values in the order they first appear. To sort them alphabetically, wrap the formula in SORT:

=SORT(UNIQUE(A2:A100))

This is one of the simplest ways to sort data with formula in excel, and it works on the list without touching the source.

Google Sheets

Google Sheets has UNIQUE with the same arguments, so the formulas in this article work there too. You can also wrap UNIQUE around FILTER in Sheets to drop blanks.

Tips

  • Leave room below the formula for the list to grow.
  • Keep a copy of your data before you use Remove Duplicates on the Data tab.
  • If a formula shows #SPILL!, see how to fix #spill error in excel for the steps to clear it.

The complete guide to dynamic arrays

What Dynamic Array Formulas Are in Excel
Read the guide

Keep exploring

Guides from other topics

All topics →

How to Look Up Data in Excel

How lookups work in Excel, with VLOOKUP, XLOOKUP and INDEX with MATCH, how to set up your data, and how to choose the right function for the job.

Lookups 3 min read