FormulaCamp
Completed
← All functions
Text

TRIM

Removes extra spaces.

Syntax

TRIM(text)

Example: =TRIM(A2)

Available in: All versions

TRIM removes leading and trailing spaces from text and reduces any run of spaces inside to a single space: =TRIM(text). It is the first step in cleaning imported data before lookups or counts.

When to use it

Arguments explained

Worked examples

Clean extra spaces

A
1Name
2 John Smith

Formula: C1: =TRIM(A2)

Result: John Smith

Leading and trailing spaces are removed and the three inner spaces become one.

Length after cleaning

A
1Name
2 John Smith

Formula: C1: =LEN(TRIM(A2))

Result: 10

The raw text has 16 characters; the cleaned text has 10.

Make a lookup work

ABC
1NameStaff
2 Ben Ana
3Ben
4Cara

Formula: E1: =MATCH(TRIM(A2),C2:C4,0)

Result: 2

Without TRIM, " Ben " would not match "Ben" and MATCH would return #N/A.

Try it

A tiny spreadsheet with example data. Edit the formula or any number and see the result.

Formula in D2: =TRIM(A4)

Example spreadsheet for TRIM
ABCD
1TextOtherResult
2Alice Johnsonalice johnsonextra spaces
3[email protected][email protected]
4 extra spaces
5SKU-2026-0415
6iced coffee, tea, sugar
7Order 417 shipped
Result in D2: extra spaces
Practice this in a lesson: Cleaning Data

Common errors and how to fix them

Related functions

Frequently asked questions

Why does TRIM not work on my data?
The spaces are probably non-breaking (CHAR(160)). Replace them with SUBSTITUTE before TRIM.
Does TRIM remove all spaces?
No. It leaves a single space between words. Use SUBSTITUTE(A2," ","") to remove all of them.
Can TRIM clean a whole column?
In Microsoft 365, =TRIM(A2:A100) spills a cleaned column.
Does TRIM change the original cell?
No. It returns a new value.

Practice

More in Text