Text

TRIM Formula

TRIM removes all extra spaces from text, leaving only single spaces between words. It strips leading spaces, trailing spaces, and reduces multiple consecutive spaces to one. TRIM is essential for cleaning data imported from external sources, databases, or web scraping where spacing is inconsistent.

Syntax

TRIM(text)
ParameterDescription
text Parameter of the TRIM function.
Try TRIM in Viztab — free, no signup

Examples

Clean up messy imported text

Formula
=TRIM(A2)
Returns: "John Smith" — removes extra spaces from " John Smith "

Fix VLOOKUP failures from spaces

Formula
=VLOOKUP(TRIM(A2), D:E, 2, FALSE)
Returns: the correct lookup result after trimming hidden spaces that were causing #N/A errors

Clean and compare

Formula
=EXACT(TRIM(A2), TRIM(B2))
Returns: TRUE if the two cells match after removing extra spaces from both

Common Errors

#VALUE!

The cell contains an error value. TRIM only works on text strings, not error values like #N/A or #REF!.

Tips

Does not remove non-breaking spaces

Web data often contains non-breaking spaces (char 160). Use SUBSTITUTE(A1, CHAR(160), " ") before TRIM.

TRIM whole column

Apply TRIM to an entire column of imported data before doing lookups or comparisons — hidden spaces are the #1 cause of failed VLOOKUPs.

Combine with CLEAN

=TRIM(CLEAN(A1)) removes both non-printable characters (CLEAN) and extra spaces (TRIM) for thorough data cleaning.

Try TRIM in Viztab

Import your data and use TRIM with 370+ other formulas. No signup required.

Open Viztab

Related Formulas