Skip to content

How to remove extra spaces in Excel in Excel

Clean leading, trailing and repeated spaces with TRIM, and handle the non-breaking spaces that TRIM misses with SUBSTITUTE.

Imported text often carries invisible spaces: a gap before a name, two spaces between words, a trailing space after the last letter. They look harmless, but they break lookups, because "Alpha" and "Alpha " are different values, and they make duplicates hard to spot.

TRIM removes every leading and trailing space and reduces runs of spaces between words to one:

=TRIM(A2)

It is the first step when a lookup fails for no visible reason.

TRIM only handles the ordinary space, character 32. Text copied from web pages and PDFs often contains non-breaking spaces, character 160, which look the same but which TRIM leaves alone. Replace them with ordinary spaces first, then trim:

=TRIM(SUBSTITUTE(C2, CHAR(160), " "))

If a cell still looks off after that, other invisible characters may be present. CLEAN removes the non-printing control characters, such as line breaks from copied text, and can wrap TRIM: =TRIM(CLEAN(A2)).

Do not use SUBSTITUTE to delete every space unless you really mean to. That would squash the words together.

The ribbon alternative is Find and Replace: press Ctrl+H, type two spaces in Find what and one space in Replace with, and choose Replace All, repeating until nothing changes. It edits the data in place and does not remove leading or trailing spaces on its own, so the formula route is more thorough. The Logic and text track has a lesson on cleaning data.

3 ways to do it

1TRIM

=TRIM(A2)

  1. In B2 type =TRIM(A2) and press Enter.
  2. Fill down. Leading and trailing spaces go, and repeated spaces between words become one.
  3. To replace the original, copy the results and paste over them with Paste Special > Values.

2TRIM with SUBSTITUTE for non-breaking spaces

=TRIM(SUBSTITUTE(C2,CHAR(160)," "))

  1. Replace character 160 with an ordinary space using SUBSTITUTE and CHAR(160).
  2. Wrap the result in TRIM to tidy the spacing.

3Find and Replace (in place)

  1. Select the cells and press Ctrl+H.
  2. Type two spaces in Find what and one space in Replace with, then choose Replace All.
  3. Repeat until Excel reports no replacements. Leading and trailing spaces remain, so the formula is more thorough.

Try it yourself

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, remove the leading, trailing and repeated spaces from A2. Fill down to B7.

Answer in B2, then it fills down to B7.

B2
A
B
C
D
E
F
1
Name (raw)
Name (clean)
Name (pasted from web)
Name (clean)
2
Alpha Supplies
Alpha Supplies
3
Bravo Print
Bravo  Print
4
Cedar Ridge Foods
 Cedar Ridge Foods
5
Delta Works
Delta Works 
6
Echo Valley
Echo Valley
7
Fenwick Tools

Learn it properly, one graded sheet at a time.

Logic and text covers this in lesson 7, TRIM and CLEAN.