Excel function

TRIMfunction

Removes leading and trailing spaces and leaves single spaces between words.

All versions
=TRIM(" Excel functions guide ")

Text27 chars

1·
2·
3E
4x
5c
6e
7l
8·
9·
10·
11f
12u
13n
14c
15t
16i
17o
18n
19s
20·
21·
22g
23u
24i
25d
26e
27·

Result21 chars

1E
2x
3c
4e
5l
6·
7f
8u
9n
10c
11t
12i
13o
14n
15s
16·
17g
18u
19i
20d
21e

Add or remove spaces in the text. A dot (·) marks a space. Try breaking it on purpose to see the errors.

Result

Excel functions guide

text

The text whose spaces you want to clean up.

What is the TRIM function?

=TRIM(text)

TRIM removes all spaces at the start and end of a text and reduces runs of spaces between words to one. Use it to clean data pasted from other programs or the web.

When VLOOKUP or COUNTIF can't find a matching value, invisible spaces are often the cause. In the strip a dot (·) is a space, and playing the steps shows the removed spaces in red.

Arguments

text
The text or cell to clean up.

TRIM examples

  1. Example 1. Clean up doubled spaces

    =TRIM(" Excel functions guide ")

    Removes 2 leading, 1 trailing and the extra spaces between words: "Excel functions guide".

  2. Example 2. Example from Microsoft

    =TRIM(" First Quarter Earnings ")

    Removes the leading and trailing spaces: "First Quarter Earnings".

  3. Example 3. Clean before a lookup

    =VLOOKUP(TRIM(A2), table, 2, FALSE)

    Removes spaces from the lookup value first.

Common mistakes

FAQ

Does it change the original data?
No. The result appears in the formula cell. To replace the original, copy the result and paste as values.
How do I count the spaces?
=LEN(A2)-LEN(TRIM(A2)) counts the spaces TRIM would remove.