Function · Text

Excel TRIM function

The Excel TRIM function removes extra spaces from text. It does not remove the non-breaking space you get from a web page.

All current Excel versions. Also in Excel for the web and Google Sheets.

Syntax =TRIM(text)

TRIM
=TRIM("  Maria  Lopez  ")

Arguments

NameRequiredWhat to pass
textRequiredThe text to clean. Leading and trailing spaces go away. Repeated spaces between words become one space.

Examples

A name pasted with extra spaces

=TRIM(B1)

Result Maria Lopez

=TRIM(B1)B2
Name
AB
1Raw Maria Lopez
2CleanMaria Lopez
A picture of the sheet, not a live calculator. The spaces in B1 are ordinary spaces, character 32.

TRIM deletes spaces at both ends and collapses runs of spaces between words to a single space. Maria Lopez becomes Maria Lopez. The spaces it understands are ordinary spaces, character 32.

A name copied from a web page often has a non-breaking space, character 160, where you see a gap. TRIM leaves that character in place, so the cell still fails an exact match against Maria Lopez. SUBSTITUTE the non-breaking space with a normal space first. The LAMBDA how-to wraps that pair of steps in one name, because the two-function version is easy to forget.