Practice free

TRIM function

TRIM removes leading and trailing spaces from text and collapses repeated spaces between words to one. It is the first step in cleaning names and imported data.

Example

Read it as a sentence: remove the extra spaces at the start, at the end, and between words in F6, which gives Hello World.

Practice this in the app

Syntax

TRIM(text)

text (required)
The text to tidy.

Returns: The text with extra spaces removed.

What Excel actually returns

Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.

FormulaExcel showsCase
=LEN(TRIM(CHAR(160)&"a"&CHAR(160))) 3 Non-breaking space kept?
=TRIM(123) 123 Number
=TRIM("") Empty
=LEN(TRIM("a"&CHAR(9)&"b")) 3 Tab kept?
=TRIM(Data!F6) Hello World Leading, trailing, inner spaces
=TRIM(Items!B2:B3) Boxer cartridge Range spills

The Data sheet these formulas read

A cell that starts with = holds that formula.

The Items sheet these formulas read

Watch out for

  • Does not remove non-breaking spaces (code 160).
  • Result is text.

Where it works

Excel
TRIM is in every version of Excel from 2007 on.
Google Sheets
Same name, same behaviour for everyday use.

Part of Text functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .