Get Unique Values From Multiple Columns in Excel
By ExcelReady TeamUpdated 7 min read
The short answer
To get unique values from multiple columns in Excel, turn the columns into one list with TOCOL, then pass it to UNIQUE: =UNIQUE(TOCOL(A2:C5,1)). The 1 skips blank cells. Wrap it in SORT for an A to Z list. TOCOL needs Microsoft 365 or Excel 2024. In older versions, stack the columns into one and use Remove Duplicates.
Key takeaways
- UNIQUE on a multi-column range returns unique rows, not unique values. Flatten the range with TOCOL first.
- =SORT(UNIQUE(TOCOL(A2:C5,1))) lists every distinct value from three columns, A to Z, without blanks.
- Use VSTACK to combine columns that are not next to each other, or that sit on different sheets.
- COUNTA around the formula counts the unique values.
- TOCOL and VSTACK need Microsoft 365 or Excel 2024. Older versions can stack the columns and use Remove Duplicates.
On this page+
- Why UNIQUE alone doesn't work on several columns
- How to get unique values from multiple columns with TOCOL
- How to combine columns that aren't next to each other
- How to count unique values across multiple columns
- How to get unique rows (combinations) instead
- Another formula: TEXTJOIN and TEXTSPLIT
- How to do it in Excel 2021 and older versions
- Common problems
- Practise it
To get unique values from multiple columns in Excel, first turn the columns into one list, then remove the repeats. In Microsoft 365 and Excel 2024, one formula does both: =UNIQUE(TOCOL(A2:C5,1)). This guide explains why UNIQUE alone doesn't do it, shows how to sort, count and combine separate lists, and gives two methods for older versions of Excel.
The examples use a small shift rota in A1:C5. Some names appear in several weeks, and B4 is empty.
| A | B | C | |
|---|---|---|---|
| 1 | Week 1 | Week 2 | Week 3 |
| 2 | Ana | Ben | Ana |
| 3 | Ben | Cara | Dev |
| 4 | Cara | Ben | |
| 5 | Eli | Ana | Cara |
Five different people worked: Ana, Ben, Cara, Dev and Eli. The goal is a formula that lists those five, once each.
Why UNIQUE alone doesn't work on several columns#
UNIQUE compares whole rows when you give it more than one column. So =UNIQUE(A2:C5) returns all four rows unchanged, because no two rows are exactly the same. Ana still appears three times.
That is useful when you want unique combinations (more on that below), but not when you want one list of values. The fix is to flatten the columns into a single column first. The UNIQUE function guide covers the other arguments, and the article on the UNIQUE function covers the single-column basics.
How to get unique values from multiple columns with TOCOL#
TOCOL turns any range into one column. UNIQUE then removes the repeats.
=UNIQUE(TOCOL(A2:C5,1))Type it in an empty cell, such as E2, and the result spills down into the cells below (it fills them automatically):
| E |
|---|
| Ana |
| Ben |
| Cara |
| Dev |
| Eli |
TOCOL(A2:C5,1)reads the range into one column. The 1 tells it to skip blank cells. Without it, the empty B4 becomes a 0 in your list.UNIQUE(...)keeps the first appearance of each name.
TOCOL reads row by row by default: Ana, Ben, Ana, then Ben, Cara, Dev, and so on. To read column by column instead, add TRUE as the third argument: =UNIQUE(TOCOL(A2:C5,1,TRUE)) returns Ana, Ben, Cara, Eli, Dev, the order in which each name first appears going down Week 1, then Week 2, then Week 3.
TOCOL needs Microsoft 365 or Excel 2024. For Excel 2021 and older, see the last method below.
How to sort the unique list#
Wrap the formula in SORT for an A to Z list:
=SORT(UNIQUE(TOCOL(A2:C5,1)))For Z to A, add the sort order: =SORT(UNIQUE(TOCOL(A2:C5,1)),,-1). The two commas skip SORT's second argument, which picks the column to sort by. The SORT function guide explains every argument, and the article on a sorted unique list shows more ways to sort the results.
How to combine columns that aren't next to each other#
TOCOL needs one block of cells. If your lists are in columns that aren't side by side, or on different sheets, join them with VSTACK first. VSTACK stacks ranges on top of each other.
=SORT(UNIQUE(TOCOL(VSTACK(A2:A5,C2:C5),1)))This combines Week 1 and Week 3 only and returns Ana, Ben, Cara, Dev, Eli. Across sheets, the pattern is the same:
=SORT(UNIQUE(TOCOL(VSTACK(North!A2:A50,South!A2:A50),1)))Keep TOCOL with the 1 around VSTACK: it removes the blanks at the bottom of each range. VSTACK needs Microsoft 365 or Excel 2024. The guide to combining data from multiple sheets covers VSTACK and Power Query in more detail.
How to count unique values across multiple columns#
To count instead of list, wrap the formula in COUNTA:
=COUNTA(UNIQUE(TOCOL(A2:C5,1)))The result is 5. Make sure TOCOL has the 1, or the blank cell is counted as an extra value. The article on counting unique values shows other counting methods, including ones for older Excel.
How to get unique rows (combinations) instead#
Sometimes "unique from multiple columns" means unique combinations, such as every Region and Product pair that appears in a sales list. That is what UNIQUE does on its own when you give it several columns:
| A | B | |
|---|---|---|
| 1 | Region | Product |
| 2 | North | Laptop |
| 3 | South | Laptop |
| 4 | North | Laptop |
| 5 | North | Monitor |
=UNIQUE(A2:B5) returns three rows: North Laptop, South Laptop and North Monitor. Row 4 is dropped because it repeats row 2 exactly. UNIQUE and SORT need Excel 2021 or Microsoft 365. The modern Excel functions lesson practises spill formulas like this.
Another formula: TEXTJOIN and TEXTSPLIT#
You can also join every value into one long piece of text and split it back into a column. This is the method in the exercise on this page:
=SORT(UNIQUE(TEXTSPLIT(TEXTJOIN(",",TRUE,A2:C5),,",")))TEXTJOIN joins the names with commas and skips blanks (that is the TRUE). TEXTSPLIT splits at each comma, and the two commas before "," mean "split into rows, not columns". It returns the same five names. Like TOCOL, TEXTSPLIT needs Microsoft 365 or Excel 2024, so TOCOL is usually the simpler choice. The join-and-split trick has limits: it breaks if a value contains a comma, numbers come back as text, and TEXTJOIN can't return more than 32,767 characters.
How to do it in Excel 2021 and older versions#
Without TOCOL, VSTACK or TEXTSPLIT, stack the values by hand and then remove the repeats:
- Copy each column and paste it under the first one, so all values sit in one column.
- Select that column and choose Data > Remove Duplicates, then click OK.
- Sort it with Data > Sort A to Z if you like.
This works in every version, but the list does not update when the data changes. In Excel 2021 you can keep it live instead: keep the stacked column as a helper column and point =SORT(UNIQUE(...)) at it, so new names added to the helper column appear in the list. The comparison of UNIQUE vs Remove Duplicates explains when each one fits.
Common problems#
- A 0 in the list. TOCOL is missing the 1, so a blank cell became 0.
- #SPILL! The cells below the formula aren't empty. Clear them so the list has room.
- Near-duplicates. "Ana" and "Ana " (with a trailing space) are different to UNIQUE. Clean them with TRIM:
=UNIQUE(TRIM(TOCOL(A2:C5,1))). - Capitals. UNIQUE isn't case-sensitive, so "ana" and "Ana" count as one, and the first spelling wins.
Practise it#
Try the exercise on this page: it uses the join-and-split method on the shift rota, and you can check that five names come back. Then practise the UNIQUE function in a live spreadsheet, where you type each formula and see the spill result checked instantly.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
List every person who worked a shift, once each and A to Z. The practice sheet doesn't support TOCOL, so use the join-and-split method in E2: =SORT(UNIQUE(TEXTSPLIT(TEXTJOIN(",",TRUE,A2:C5),,","))).
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Week 3 | Everyone | ||||
| 2 | Ana | |||||
| 3 | Dev | |||||
| 4 | Cara | Ben | ||||
| 5 | Cara | |||||
| 6 | ||||||
| 7 | ||||||
| 8 |
Tip: TEXTJOIN joins all the names with commas, TEXTSPLIT splits them back into one column, then UNIQUE and SORT tidy the list.
Practise this in a lesson
Frequently asked questions
How do I get unique values from two columns in Excel?
If the columns are side by side, use =UNIQUE(TOCOL(A2:B20,1)). If they are apart or on different sheets, stack them first: =UNIQUE(TOCOL(VSTACK(A2:A20,D2:D20),1)). Both need Microsoft 365 or Excel 2024.
Why does UNIQUE return the same names more than once across columns?
On a range with several columns, UNIQUE compares whole rows, so it returns unique rows rather than unique values. Turn the range into a single column with TOCOL first.
How do I count unique values across multiple columns?
Wrap the list in COUNTA: =COUNTA(UNIQUE(TOCOL(A2:C5,1))). The 1 in TOCOL skips blanks so they aren't counted as a value.
How do I get unique values from multiple columns without UNIQUE?
Copy each column into one long column, select it and use Data > Remove Duplicates. The result does not update by itself, so repeat it when the data changes.
Is UNIQUE case-sensitive?
No. UNIQUE treats Ana and ANA as the same value and keeps the first one it finds. Extra spaces do count as a difference, so clean the data with TRIM first.