# How to fix spacing in comma-separated lists in Excel

Split at the commas, trim each item and join them back: =TEXTJOIN(", ",TRUE,TRIM(TEXTSPLIT(A2,","))).

**Excel:** `=TEXTJOIN(", ",TRUE,TRIM(TEXTSPLIT(A2,",")))` (Excel 2024 and Microsoft 365)

**Google Sheets:** `=JOIN(", ",ARRAYFORMULA(TRIM(SPLIT(A2,","))))`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| Tags (messy) | Clean |
| red,blue ,  green |  |
| oak , walnut,birch |  |
| steel |  |
| pine,maple |  |
| brass ,steel , copper |  |

Formula in B2, filled to B6: `=TEXTJOIN(", ",TRUE,TRIM(TEXTSPLIT(A2,",")))`

Result: red, blue, green; oak, walnut, birch; steel; pine, maple; brass, steel, copper

## How it works

TEXTSPLIT breaks the list at every comma, whatever spaces surround it. TRIM cleans each item, and TEXTJOIN puts them back with a consistent ", " between them. TRUE also drops empty items, so a double comma doesn't leave a gap.

## Other ways

- `=TRIM(SUBSTITUTE(SUBSTITUTE(TRIM(A2)," ,",","),",",", "))`: Works in every version: remove spaces before commas, put one after each, and let TRIM collapse the doubles.

## Common mistakes

- The SUBSTITUTE version keeps empty items: "a,,b" becomes "a, , b". The TEXTJOIN version drops them.
- Items that differ only in case or spelling ("Red", "red") stay separate. Clean them with LOWER or a lookup table.

## Questions

**How do I also remove duplicate items?**

Add UNIQUE, splitting into rows: `=TEXTJOIN(", ",TRUE,UNIQUE(TRIM(TEXTSPLIT(A2,,","))))`.

**How do I use a semicolon instead?**

Change both delimiters: `=TEXTJOIN("; ",TRUE,TRIM(TEXTSPLIT(A2,",")))`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/fix-spacing-in-comma-separated-lists
