Text function

How to use TRIM in Excel

Removes extra spaces.

Syntax

TRIM(text)
textText or a cell

Example

Here’s TRIM on a small table of orders. The highlighted cells are the ones the formula reads.

G2
fx
=TRIM(" Maya ")
A
B
C
D
E
F
1
Order
Region
Rep
Units
Price
Revenue
2
1001
East
Maya
4
12
48
3
1002
West
Omar
2
30
60
4
1003
East
Lena
7
12
84
5
1004
North
Maya
1
45
45
6
1005
West
Lena
5
30
150
7
1006
East
Omar
3
18
54
8
1007
North
Lena
6
12
72
9
1008
West
Maya
8
18
144
MayaResult of =TRIM(" Maya ")

Edit this formula live Change the ranges and watch the answer update. Free, no sign-up.

Common mistakes with TRIM

It doesn’t remove non-breaking spaces

Text pasted from the web often contains CHAR(160). Use SUBSTITUTE(A2,CHAR(160)," ") first.

It keeps single spaces between words

TRIM removes leading, trailing and doubled spaces only.

What the error messages mean

Type these slips into Gridwise and this is the feedback you get:

Leaving off the closing bracket

=TRIM(" Maya "

Parentheses don’t match. You have 1 opening and 0 closing parentheses. Every ( needs a ).

Questions

What does the TRIM function do in Excel?

Removes extra spaces. The syntax is TRIM(text).

Why is my TRIM formula giving the wrong answer?

It doesn’t remove non-breaking spaces: Text pasted from the web often contains CHAR(160). Use SUBSTITUTE(A2,CHAR(160)," ") first. It keeps single spaces between words: TRIM removes leading, trailing and doubled spaces only.

Does TRIM work in Google Sheets?

Most Excel functions, including the core ones on this page, work the same way in Google Sheets. A few newer functions arrived in Sheets later or behave slightly differently, so test it on your own data.

Related functions