Going Stellar

Home/Google Sheets reference

Google Sheets function · Text

TRIM in Google Sheets: syntax and examples

TRIM removes spaces at the start and end of a text and reduces repeated spaces inside it to one. Run it on imported or typed data before you use it as a lookup key.

Syntax

TRIM(text)

Arguments

ArgumentTypeRequiredWhat it does
textstringyesThe text to clean.

Examples

The examples use this table, starting in A1:

Name
Ana Pop
Radu
x y
42
=TRIM(A2)

Result: Ana Pop

Leading and trailing spaces go, and runs of spaces inside shrink to one.

Run in a Google Sheet (English US locale) on .

=LEN(A2)

Result: 13

Length before cleaning, for comparison.

Run in a Google Sheet (English US locale) on .

=LEN(TRIM(A2))

Result: 7

Length after cleaning.

Run in a Google Sheet (English US locale) on .

=TRIM(A4)

Result: x y

Spaces inside the text are also reduced to a single space.

Run in a Google Sheet (English US locale) on .

=ARRAYFORMULA(TRIM(A2:A5))

Result:

Ana Pop
Radu
x y
42

Clean a whole column at once.

Run in a Google Sheet (English US locale) on .

Common errors

  • TRIM does not remove the non-breaking space, CHAR(160), common in data pasted from web pages. Use SUBSTITUTE(A1, CHAR(160), " ") first.
  • The result is text. TRIM(" 42 ") looks like a number but ISNUMBER says FALSE. Wrap it in VALUE when you need a number.
  • It collapses spaces inside the text too, so it also changes text where double spaces were intended.

Compared with Excel

Same syntax in Excel.

Sources

  1. TRIM (Docs Editors Help)

Markdown version · All functions