How to Remove Spaces in Excel (Extra, Leading, All)
By ExcelReady TeamUpdated 6 min read
The short answer
To remove extra spaces in Excel, use =TRIM(A2). It deletes spaces at the start and end and turns double spaces between words into single ones. To remove every space, use =SUBSTITUTE(A2," ",""). If spaces survive both, they are non-breaking spaces from the web: use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
Key takeaways
- TRIM removes leading and trailing spaces and reduces gaps between words to one space.
- SUBSTITUTE(A2," ","") removes every space, including the ones between words.
- Spaces copied from web pages are often non-breaking spaces, CHAR(160), which TRIM can't remove.
- Use LEN to check whether a cell has hidden spaces before and after cleaning.
- Paste the cleaned results as values to replace the original data.
On this page+
To remove spaces in Excel, use TRIM for extra spaces and SUBSTITUTE for all of them. TRIM cleans up spaces at the start and end of a cell and turns double spaces into single ones, which fixes most imported data. This guide shows when to use each, how to deal with stubborn spaces from websites, and how to find hidden spaces before they break your formulas.
Extra spaces matter because Excel sees "Maria Lopez " and "Maria Lopez" as different values. That one hidden space can make a VLOOKUP return #N/A or a COUNTIF return 0.
Which method do you need?#
Pick the method based on which spaces you want gone:
| You want to remove | Method | " Maria Lopez " becomes |
|---|---|---|
| Leading, trailing and extra spaces | =TRIM(A2) | Maria Lopez |
| Every space | =SUBSTITUTE(A2," ","") | MariaLopez |
| Non-breaking spaces from the web | =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) | Maria Lopez |
| Spaces in a whole column, no formula | Find and Replace | Depends on what you replace |
How to remove extra spaces with TRIM#
TRIM removes every space except single spaces between words. It takes just one argument:
=TRIM(A2)With " Maria Lopez " in A2, the result is Maria Lopez. The two leading spaces, the extra two in the middle and the trailing space are all gone. Here's how to clean a whole column:
- In B2, type
=TRIM(A2)and press Enter. - Fill it down to the last row (double-click the fill handle).
- Copy column B, then paste it over column A as values: Paste Special > Values (Windows: Ctrl+Alt+V, then V; Mac: ⌃⌘V).
- Delete column B.
TRIM works in every version of Excel. The TRIM function guide has a quick reference.
How to remove all spaces with SUBSTITUTE#
When no spaces should be left at all, such as in phone numbers, IDs or postcodes, replace every space with nothing:
=SUBSTITUTE(A2," ","")The second argument is a space in quotes, and the third is two quotes with nothing between them. "AB12 3CD" becomes AB123CD. SUBSTITUTE swaps every copy of the text you name, so it is also the tool for dashes, dots and other characters. The guide to removing characters in Excel covers those, and the SUBSTITUTE function guide shows the optional fourth argument.
If the cleaned value is a number, such as "1 250" with a space as a thousands separator, wrap it in VALUE so you can do maths with it:
=VALUE(SUBSTITUTE(A2," ",""))The result is the number 1250.
Why TRIM doesn't remove some spaces#
If TRIM leaves spaces behind, they are probably non-breaking spaces. Web pages use them to keep words together, and they come along when you copy and paste from a browser. To Excel, a non-breaking space is character 160, not the normal space, character 32. TRIM only removes character 32.
Turn the non-breaking spaces into normal ones first, then trim:
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))CHAR(160) produces the non-breaking space, SUBSTITUTE changes each one to a normal space, and TRIM cleans up. If the data also has line breaks or other invisible characters, add CLEAN: =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))). CLEAN removes non-printing characters such as line breaks (character 10).
How to find cells with hidden spaces#
Spaces at the end of a cell are invisible, so check with LEN, which counts every character, including spaces:
=LEN(A2)<>LEN(TRIM(A2))This returns TRUE when the cell has extra spaces. For "Tom Becker", LEN gives 11 and LEN of the trimmed text gives 10, so the result is TRUE. Fill it down a column, then filter for TRUE to see every messy row.
To count them all at once, use =SUMPRODUCT(--(LEN(A2:A100)<>LEN(TRIM(A2:A100)))).
Remove spaces with Find and Replace#
Find and Replace removes spaces without a helper column, which is handy for a quick fix. To remove every space in a range:
- Select the cells.
- Press Ctrl+H (Mac: ⌃H) to open Find and Replace.
- In Find what, type a single space. Leave Replace with empty.
- Click Replace All.
This removes all spaces, including the ones between words, so it suits codes and numbers rather than names. To fix double spaces only, find two spaces and replace with one, then click Replace All again until Excel finds nothing. See the guide to Find and Replace in Excel for more options.
Remove spaces with Power Query#
Power Query is useful when you clean the same kind of file again and again. Select the data, choose Data > From Table/Range, right-click the column header and pick Transform > Trim. Click Close & Load to send the result back to a sheet, and next time just click Refresh.
Be aware that Power Query's Trim only removes spaces at the start and end. Unlike the TRIM function, it leaves double spaces between words. To fix those too, use Replace Values in Power Query to swap two spaces for one, or clean the column with the TRIM function instead.
One more thing to know: TRIM and SUBSTITUTE always return text. If you trim a column of numbers, wrap the formula in VALUE so the results still add up.
Spaces and other clean-up tools#
Spaces are often only one part of a messy column. If names and surnames are in one cell separated by spaces, Text to Columns can split them, but trim first, or double spaces create empty columns. For the full routine of trimming, fixing case, removing duplicates and converting text numbers, read the guide to cleaning messy data. And for swapping one piece of text for another, see SUBSTITUTE and REPLACE.
Practise it#
Hidden spaces are one of the most common reasons formulas fail in real jobs and in tests. Practise cleaning text in a live spreadsheet: you type TRIM, SUBSTITUTE and CLEAN formulas, and it checks each result instantly. Then try the basic Excel test to see how quickly you can spot and fix dirty data.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
The name in A2 has spaces at the start, in the middle and at the end. In B2, use TRIM to clean it.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Clean name | |||
| 2 | Maria Lopez | |||
| 3 | Tom Becker | |||
| 4 | Aiko Sato | |||
| 5 | Luis Ortega | |||
| 6 | ||||
| 7 | ||||
| 8 |
Tip: TRIM takes one argument: the cell to clean.
Practise this in a lesson
Frequently asked questions
How do I remove trailing spaces in Excel?
Use =TRIM(A2) in a helper column. It removes spaces at the end and the start of the text, and extra spaces between words, then you paste the results back as values.
How do I remove all spaces in Excel?
Use =SUBSTITUTE(A2," ","") to replace every space with nothing. Or select the cells, press Ctrl+H, type a space in Find what, leave Replace with empty and click Replace All.
Why is TRIM not removing spaces?
The spaces are probably non-breaking spaces, character 160, which often come from web pages. Replace them first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
How do I find cells with extra spaces?
Compare the length before and after trimming: =LEN(A2)<>LEN(TRIM(A2)) returns TRUE for cells with extra spaces.
How do I remove spaces from numbers in Excel?
Use =VALUE(SUBSTITUTE(A2," ","")). SUBSTITUTE removes the spaces and VALUE turns the result back into a real number you can add up.