SheetsLessons
Text function

TRIM function in Google Sheets

TRIM removes spaces from the start and end of text and collapses runs of spaces in between down to one. Hidden extra spaces are the most common reason lookups fail on data that "looks right".

Syntax

=TRIM(text)
text
The text to clean.

Practice TRIM

Task 1 of 2

Clean up the extra spaces in the name in A2. Answer in B2.

B2
fx

Tip: while typing a formula, click a cell or drag across cells to insert references. Press Enter to check, and Tab to accept a function suggestion.

TRIM examples

Each example below runs against this sample sheet. The results are calculated by the same engine as the practice grid.

ABC
1Raw nameSKUNote
2  maya   PATEL ELC-0427-NYRefund requested
3leo rossiFUR-1180-TXShipped
4AVA KIMOFC-0093-CARefund issued
Messy imported data
FormulaResultWhat it shows
=TRIM(A2)maya PATELLeading, trailing and double spaces removed.
=PROPER(TRIM(A2))Maya PatelClean up a messy name completely.
=LEN(A2) - LEN(TRIM(A2))5How many extra spaces there were.

Tips and common mistakes

  • Google Sheets also has Data › Data cleanup › Trim whitespace, which cleans cells in place without a formula.

Related functions