Use the TRIM function: =TRIM(A2) removes leading, trailing and repeated spaces, leaving only single spaces between words.
=TRIM(A2)
When you copy data from another system or paste text from emails, cells often contain extra spaces. These hidden spaces break lookups, sorting and filters. TRIM cleans them up so your data matches and formulas work.
Step by step
- Click an empty cell next to your data, for example D2.
- Type
=TRIM(A2)and press Enter. This returns the text from A2 without extra spaces. - Copy the formula down to the other rows by dragging the fill handle.
- If you want to replace the original text, copy the cleaned cells, then use Paste Special › Values over the original column and delete the helper column.
Try it here
Examples
1 Remove extra spaces from a name
The formula =TRIM(A2) takes the text in A2 and removes leading, trailing and repeated spaces. It returns 'John Smith' with a single space between the names.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | ||||
| 2 | John Smith | John Smith | |||
| 3 | Mary Jones | ||||
| 4 | Peter Pan | ||||
| 5 |
=TRIM(A2)2 Remove spaces from a code
If you need to remove all spaces, not just extra ones, use =SUBSTITUTE(A2," ",""). This example removes every space from a product code so it can be matched.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Code | ||||
| 2 | AB 123 CD | AB123CD | |||
| 3 | XY 456 | ||||
| 4 | Z 789 | ||||
| 5 |
=SUBSTITUTE(A2," ","")Other ways to do it
| Formula | Use it when |
|---|---|
=CLEAN(A2) | Use when the text contains non-printing characters (like line breaks) in addition to spaces. Combine with TRIM: =TRIM(CLEAN(A2)). |
=SUBSTITUTE(A2," ","") | Use when you want to remove all spaces, including single spaces between words. |
Practise it
Free exercises with instant feedback. No sign-up needed.
Common mistakes
- TRIM only removes spaces, not other whitespace characters like non-breaking spaces (CHAR(160)). Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) to convert non-breaking spaces to regular spaces first.
- Forgetting to paste values when replacing original data, leaving formulas that break if source cells change. After cleaning, copy the results and use Paste Special › Values to replace the original data.
Questions people also ask
How do I remove extra spaces between words but keep single spaces?
Use =TRIM(A2). It keeps one space between words and removes all other spaces.
Can I remove spaces from multiple cells at once?
Yes. Enter the formula in the first cell, then drag the fill handle down to apply it to the rest.
Why does TRIM not remove all spaces?
TRIM does not remove non-breaking spaces (CHAR(160)). Use SUBSTITUTE to replace them with regular spaces first.
Functions used
Every formula on this page was checked by SheetSkill’s spreadsheet engine. All how-to guides