Remove Duplicates Within a Cell in Excel
By ExcelReady TeamUpdated 6 min read
The short answer
To remove duplicates within a cell, split the text into items, keep each item once, and join them back. In Microsoft 365 or Excel 2024, use =TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,,", "))). For "red, blue, red, green" it returns "red, blue, green". The two commas in TEXTSPLIT split the items into rows, which UNIQUE needs.
Key takeaways
- The formula is =TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,,", "))): split, keep unique, join.
- Split into rows (note the two commas). UNIQUE compares rows, so a single row of items comes back unchanged.
- Add TRIM when the spacing after commas is uneven: UNIQUE(TRIM(TEXTSPLIT(A2,,","))).
- UNIQUE ignores capitals, so Red and red count as the same item and the first spelling is kept.
- TEXTSPLIT needs Microsoft 365 or Excel 2024; in older versions, use Text to Columns and Remove Duplicates.
On this page+
- The formula to remove duplicates within a cell
- How the formula works, step by step
- Why UNIQUE doesn't remove anything (rows vs columns)
- How to handle uneven spaces and different separators
- Sort, count or keep only single items
- How to keep the formula short with LET
- How to remove duplicates in a cell in older Excel
- Practise it
To remove duplicates in a cell in Excel, you split the cell's text into separate items, keep one of each, and join them back together. Three functions do it in one formula: TEXTSPLIT, UNIQUE and TEXTJOIN. This guide is for anyone with cells like "red, blue, red, green", such as tags, skills, email lists or product codes exported from another system, and it also shows a method for older Excel.
The formula to remove duplicates within a cell#
Here is the whole formula for a cell where items are separated by a comma and a space:
=TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,,", ")))| A | B | |
|---|---|---|
| 1 | Colours | Without duplicates |
| 2 | red, blue, red, green, blue | red, blue, green |
| 3 | small, small, large | small, large |
| 4 | north, south | north, south |
Type the formula in B2 and fill it down (Windows: Ctrl+D; Mac: ⌘D). Each row is cleaned on its own, and the result is a single cell of text, so nothing spills. The original order is kept: each item stays where it first appeared.
This needs Microsoft 365 or Excel 2024, because TEXTSPLIT is a new function. UNIQUE needs Excel 2021 or later, and TEXTJOIN needs Excel 2019 or later.
How the formula works, step by step#
Read it from the inside out. Each function does one job:
- TEXTSPLIT(A2,,", ") splits the text at every comma and space. The empty second argument and the
", "in the third place mean "split into rows", so you get a list down a column: red, blue, red, green, blue. The TEXTSPLIT function guide covers every argument. - UNIQUE(...) keeps the first copy of each item: red, blue, green. See the UNIQUE function guide.
- TEXTJOIN(", ",TRUE,...) joins the list back into one cell with a comma and a space between items. TRUE tells it to skip empty items. The TEXTJOIN function guide explains both settings.
For a deeper look at the first step, read how to split text with TEXTSPLIT.
Why UNIQUE doesn't remove anything (rows vs columns)#
If you write TEXTSPLIT(A2,", ") with one comma, the formula returns the text unchanged. That's not a bug. TEXTSPLIT with only a column delimiter returns the items across one row, and UNIQUE compares whole rows by default. One row is always unique, so nothing is removed.
There are two fixes, and both give "red, blue, green":
=TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,,", ")))
=TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,", "),TRUE))The first splits into rows. The second keeps the row but sets UNIQUE's second argument, by_col, to TRUE so it compares columns. The first is easier to remember. The article on the UNIQUE function explains by_col in more detail.
How to handle uneven spaces and different separators#
Real data is rarely tidy. If some items have a space after the comma and some don't, split at the comma alone and clean each item with TRIM:
=TEXTJOIN(", ",TRUE,UNIQUE(TRIM(TEXTSPLIT(A2,,","))))For "red,blue, red" this returns red, blue. Without TRIM, " red" (with a space) and "red" would count as different items.
Change the delimiter to match your data:
| Items separated by | Split part |
|---|---|
| Semicolon and space | TEXTSPLIT(A2,,"; ") |
| Single space (words) | TEXTSPLIT(A2,," ") |
| Line break in the cell | TEXTSPLIT(A2,,CHAR(10)) |
If you also want a different separator in the result, change the first argument of TEXTJOIN. For example, TEXTJOIN("; ",TRUE, ...) joins with semicolons. Empty items from double commas are skipped because TEXTJOIN's second argument is TRUE; see how TEXTJOIN ignores blanks.
Sort, count or keep only single items#
Small changes to the same formula answer related questions. All examples use "red, blue, red, green, blue":
| Goal | Formula | Result |
|---|---|---|
| Unique items, sorted A to Z | =TEXTJOIN(", ",TRUE,SORT(UNIQUE(TEXTSPLIT(A2,,", ")))) | blue, green, red |
| Count the unique items | =COUNTA(UNIQUE(TEXTSPLIT(A2,,", "))) | 3 |
| Count the repeats removed | =COUNTA(TEXTSPLIT(A2,,", "))-COUNTA(UNIQUE(TEXTSPLIT(A2,,", "))) | 2 |
| Items that appear only once | =TEXTJOIN(", ",TRUE,UNIQUE(TEXTSPLIT(A2,,", "),,TRUE)) | green |
The last one uses UNIQUE's third argument, exactly_once. Set to TRUE, it keeps only items with a single copy.
Remember that UNIQUE is not case-sensitive. "Red, blue, RED" becomes "Red, blue": RED is treated as a repeat of Red, and the first spelling wins.
How to keep the formula short with LET#
If the split part appears more than once, LET gives it a name so Excel works it out only once. LET needs Excel 2021 or Microsoft 365:
=LET(items,TRIM(TEXTSPLIT(A2,,",")),TEXTJOIN(", ",TRUE,UNIQUE(items)))Read it as "let items be the trimmed pieces of A2, then join the unique items". The result is the same as the longer formula, but it is easier to read and to change later. For example, to sort as well, change only the last part to SORT(UNIQUE(items)).
When you're happy with the result, you may want plain text instead of a formula, for example before you delete the original column. Copy the results, then paste them back as values (Windows: Ctrl+Alt+V, then V; Mac: ⌘+Control+V, then choose Values).
How to remove duplicates in a cell in older Excel#
Without TEXTSPLIT, do it in steps with built-in tools:
- Copy the cell to a spare sheet.
- Use Data > Text to Columns, choose Delimited, tick Comma, and click Finish. Each item goes into its own column.
- Copy the items, right-click an empty cell and choose Paste Special > Transpose to turn them into a column.
- If a space followed each comma, the pieces now start with a space. Clean them with TRIM in a helper column and paste the results as values, or " red" and "red" will count as different items.
- Use Data > Remove Duplicates on that column. The guide to removing duplicate rows shows this step in detail.
- Join the result back with TEXTJOIN in Excel 2019, or with
&in older versions.
This works for a few cells but not for hundreds. For large lists in older Excel, Power Query (Data > From Table/Range) can split, remove duplicates and combine again in a repeatable way.
Going the other way, if you want to collect matching values from many rows into one cell without repeats, see how to list matches in one cell.
Practise it#
This formula is three modern functions working together, so practise each one. Practise the UNIQUE function in a live spreadsheet, then practise modern Excel functions like TEXTSPLIT and practise joining text with TEXTJOIN. Each lesson checks your formula as you type it. Then try the tags exercise on this page.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Cell A2 lists skill tags with repeats. Click B2 and remove the duplicates: split A2 into rows at ", ", keep unique items, and join them back with ", ".
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Unique tags | |||
| 2 | excel, sql, excel, python, sql | |||
| 3 | sql, tableau, sql | |||
| 4 | python, excel, python | |||
| 5 | ||||
| 6 | ||||
| 7 |
Tip: Work from the inside out: TEXTSPLIT(A2,,", ") splits into rows, UNIQUE keeps one of each, and TEXTJOIN(", ",TRUE, ...) joins them.
Practise this in a lesson
Frequently asked questions
How do I remove duplicate words in a cell in Excel?
Split the cell, keep the unique items and join them again: =TEXTJOIN(" ",TRUE,UNIQUE(TEXTSPLIT(A2,," "))) for words separated by spaces. Change the delimiter to match your data, such as a comma and a space.
Why does UNIQUE not remove duplicates from TEXTSPLIT?
TEXTSPLIT(A2,", ") returns one row, and UNIQUE compares whole rows by default, so it sees only one row. Split into rows with TEXTSPLIT(A2,,", ") or tell UNIQUE to compare columns with UNIQUE(...,TRUE).
Can I remove duplicates in a cell without TEXTSPLIT?
Yes, in older Excel: split the cell with Data > Text to Columns, transpose the pieces into a column, use Data > Remove Duplicates, then join them again with TEXTJOIN or the & operator.
How do I sort the items after removing duplicates?
Wrap UNIQUE in SORT: =TEXTJOIN(", ",TRUE,SORT(UNIQUE(TEXTSPLIT(A2,,", ")))). For red, blue, red, green this returns blue, green, red.
Is removing duplicates in a cell case-sensitive?
No. UNIQUE treats Red and RED as the same item and keeps whichever appears first. Excel has no simple case-sensitive version of this formula.