What is the TRIM Function
The TRIM function removes leading, trailing, and extra internal spaces from a text string. It leaves only single spaces between words. This is essential for cleaning imported data.
Formula: =TRIM(text)
Practical Example 1
A2 contains text with extra spaces around Excel Formula.
Type: =TRIM(A2)
Result: Excel Formula (with extra spaces removed)
Practical Example 2
Verify if a text was cleaned.
Type: =LEN(A2) = LEN(TRIM(A2))
Result: TRUE if no extra spaces remain
Practical Example 3
Clean data before VLOOKUP.
Type: =VLOOKUP(TRIM(A2), D:E, 2, FALSE)
Result: the lookup succeeds even if A2 had trailing spaces
Practical Example 4
Remove non-breaking spaces using SUBSTITUTE with CHAR(160).
Type: =TRIM(SUBSTITUTE(A2, CHAR(160), space))
Result: the clean text
When to Use It
TRIM is used for cleaning CSV imports, for preparing concatenated text, for fixing broken lookups, for standardizing data before matching, and for any formula where extra spaces cause problems.