ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. How to Remove Spaces in Excel (Extra, Leading, All)

How to Remove Spaces in Excel (Extra, Leading, All)

By ExcelReady Team·Updated November 1, 2026·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+
  1. Which method do you need?
  2. How to remove extra spaces with TRIM
  3. How to remove all spaces with SUBSTITUTE
  4. Why TRIM doesn't remove some spaces
  5. How to find cells with hidden spaces
  6. Remove spaces with Find and Replace
  7. Remove spaces with Power Query
  8. Spaces and other clean-up tools
  9. Practise it

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 removeMethod" 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 formulaFind and ReplaceDepends 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:

Excel formula
=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:

  1. In B2, type =TRIM(A2) and press Enter.
  2. Fill it down to the last row (double-click the fill handle).
  3. Copy column B, then paste it over column A as values: Paste Special > Values (Windows: Ctrl+Alt+V, then V; Mac: ⌃⌘V).
  4. 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:

Excel formula
=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:

Excel formula
=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:

Excel formula
=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:

Excel formula
=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:

  1. Select the cells.
  2. Press Ctrl+H (Mac: ⌃H) to open Find and Replace.
  3. In Find what, type a single space. Leave Replace with empty.
  4. 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.

fx
ABCD
1
Raw name
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

LessonCleaning messy textFix stray spaces, random capitals and inconsistent separators in imported data with TRIM, PROPER, UPPER, LOWER and SUBSTITUTE.Function guideTRIMClean imported data with Excel's TRIM: strip leading, trailing and double spaces so lookups and counts work. Examples and live practice.Function guideSUBSTITUTESwap or strip characters with Excel's SUBSTITUTE: clean phone numbers, change one occurrence and count characters with LEN. Practice it live.

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.

Sources

  • TRIM function - Microsoft Support
  • SUBSTITUTE function - Microsoft Support
  • CLEAN function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Which method do you need?
  2. How to remove extra spaces with TRIM
  3. How to remove all spaces with SUBSTITUTE
  4. Why TRIM doesn't remove some spaces
  5. How to find cells with hidden spaces
  6. Remove spaces with Find and Replace
  7. Remove spaces with Power Query
  8. Spaces and other clean-up tools
  9. Practise it

Keep reading

Text· 6 min read

How to Remove Characters From Text in Excel

To remove a specific character, use SUBSTITUTE to replace it with nothing: =SUBSTITUTE(A2,"-","") strips every dash. To remove characters by position, use RIGHT(A2,LEN(A2)-3) to drop the first three, or LEFT(A2,LEN(A2)-2) to drop the last two. To remove everything after a character, use TEXTBEFORE or LEFT with FIND.

Text· 7 min read

Clean Messy Data in Excel With TRIM, CLEAN and PROPER

Use TRIM to remove extra spaces, CLEAN to remove hidden non-printing characters, and PROPER to put a capital at the start of each word. Nest them to fix several problems at once: =PROPER(TRIM(A2)) turns " maria gonzalez" into "Maria Gonzalez". Build the clean version in a new column, check it, then paste it as values.

Text· 8 min read

SUBSTITUTE and REPLACE in Excel

Use SUBSTITUTE when you know the text you want to change: =SUBSTITUTE(A2,".","-") swaps every dot for a dash. Use REPLACE when you know the position: =REPLACE(A2,1,3,"XXX") overwrites the first three characters. SUBSTITUTE is case-sensitive and can change just one occurrence; REPLACE ignores what the characters say.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free