TRIM Function

Removes extra spaces, leaving single spaces between words.

Category

Text

Available in

All versions, Microsoft 365

Returns

Text

Taught hands-on in Level 3: Intermediate Lookups & Data Summaries - Text Functions module

Overview

TRIM removes spaces from the start and end of text and squeezes runs of spaces between words down to one.

Stray spaces are invisible but break lookups and duplicates checks — “Ana ” doesn't match “Ana”. TRIM is the first thing to try on imported data.

Syntax

=TRIM(text) Explain

Arguments

ArgumentRequired?What it does
textYesThe text or cell to clean.

Examples

Example 1 — Cleaning an import

Names from Northstar's old system came padded with spaces. LEN shows the difference.

B2fx=LEN(TRIM(A2))
AB
1Imported nameClean length
2 Ana Lopez 9
3Ben Cho 7
4 Cara Singh10
=TRIM(A2) Explain

=TRIM(A2) returns “Ana Lopez”, and its length drops from 14 to 9.

Example 2 — Fixing a lookup that won't match

Clean the lookup value inside the formula.

=XLOOKUP(TRIM(A2), Products[Name], Products[Price]) Explain

Common mistakes

  • Non-breaking spaces survive. Text copied from websites often contains character 160, which TRIM ignores. Use =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).

Notes

Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.