Learn Excel
EN

Home › Excel functions › TRIM

TRIM in Excel: Remove Extra Spaces

TRIM removes extra spaces from text: all spaces at the start and end, and double spaces between words. It's the first fix to try when a lookup returns #N/A for a value you can clearly see.

In this guide
  1. TRIM syntax
  2. Basic example
  3. Fix lookup errors
  4. Replace the original data
  5. Spaces TRIM misses
  6. Numbers with spaces
  7. FAQ

TRIM syntax

=TRIM(text)

One argument: the text or cell to clean. TRIM keeps single spaces between words.

Basic example

ABC
1Original=TRIM(A)=LEN(A) → LEN(B)
2 MangoMango7 → 5
3Banana Banana9 → 6
4Anna de VriesAnna de Vries16 → 13
=TRIM(A2)

The spaces you can't see are the problem. Use =LEN(A2) to count characters: if "Mango" has a length of 7, there are two extra spaces somewhere.

Fix VLOOKUP and MATCH errors

"Mango " with a trailing space doesn't match "Mango". You can clean the lookup value inside the formula:

=VLOOKUP(TRIM(E2), $A$2:$C$7, 3, FALSE)

If the spaces are in the table itself, clean that column once (see below) instead of trimming in every formula. More on this in the VLOOKUP guide.

Replace the original data with the trimmed version

  1. Add a helper column with =TRIM(A2) and copy it down.
  2. Copy the helper column.
  3. Select the original column and use Paste Special › Values (Ctrl+Alt+V, V, Enter).
  4. Delete the helper column.

The spaces TRIM doesn't remove

Text copied from websites often contains non-breaking spaces (character 160). They look like normal spaces, but TRIM only removes the regular space (character 32). Replace them first, then trim:

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

For line breaks and other invisible control characters from exported data, add CLEAN:

=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))

Numbers with spaces

TRIM always returns text, even if the result looks like a number. To get a real number you can calculate with, wrap it in VALUE: =VALUE(TRIM(A2)).

Frequently asked questions

Why doesn't TRIM remove all spaces?

The remaining spaces are probably non-breaking spaces (CHAR 160). Use =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).

How do I remove all spaces, including the ones between words?

Use SUBSTITUTE instead of TRIM: =SUBSTITUTE(A2, " ", "") removes every space.

Does TRIM change the original cell?

No. Formulas never change other cells. Put TRIM in a helper column and paste the results back as values.

What's the difference between TRIM and CLEAN?

TRIM removes extra spaces. CLEAN removes non-printable characters such as line breaks. They're often used together.