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.
Excel shows Hello World
F
1
2
'123
3
2024-02-29
4
TRUE
5
=1/0
6
Hello World
Data
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.
| Formula | Excel shows | Case |
|---|---|---|
=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.
F
1
2
'123
3
2024-02-29
4
TRUE
5
=1/0
6
Hello World
Data
The Items sheet these formulas read
B
1
Item
2
Boxer cartridge
3
Briar pipe
Items
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 .