
Removes leading and trailing spaces and reduces repeated internal spaces to a single space.
The Excel TRIM function removes extra spaces from text. It clears spaces at the beginning and end of the string, and it reduces repeated spaces inside the text to a single space.
TRIM is commonly used in cleanup formulas because spaces are a frequent reason why lookups and comparisons fail. Two values can look the same on screen but still not match if one of them contains an extra leading or trailing space.
Cleans spacing at the edges of the text and between words.
Returns the same text with extra spaces removed.
=TRIM(text)
text is the string or cell reference you want to clean. TRIM returns a cleaned version of that value.
TRIM is mainly about spaces. CLEAN removes some non-printing characters, and SUBSTITUTE can target a specific character directly.
| Function | Main Role | Use When |
|---|---|---|
TRIM |
Remove extra spaces | You need to clean leading, trailing, or repeated spaces |
CLEAN |
Remove non-printing characters | You suspect imported control characters |
SUBSTITUTE |
Replace a chosen character | You need to remove a specific character such as a non-breaking space |
LEN |
Count characters | You want to compare length before and after trimming |
TRIM is often used before lookup, match, and comparison formulas. Wrapping the input in TRIM can stop hidden spaces from creating false mismatches.
It is also useful in cleanup helper columns. A common pattern is =TRIM(CLEAN(A1)), which first removes non-printing characters and then removes extra spaces.
TRIM removes spaces at both ends of the string and leaves the actual text behind.
=TRIM(" Excel ") // "Excel"
=TRIM(" hello ") // "hello"
In cell F1, use TRIM on " Excel " (with spaces on both sides). Expected result: "Excel".
A trailing space is easy to miss on screen, but TRIM removes it immediately. This is one of the most common reasons to use the function.
=TRIM(A1)
// "ID-1 " -> "ID-1"
In cell F2, use TRIM on A1 ("ID-1 " with a trailing space) to clean it. Expected result: "ID-1".
TRIM does not only work at the edges. It also reduces repeated spaces inside the string to a single space.
=TRIM(B2)
// "Part 001" -> "Part 001"
In cell F3, use TRIM on B2 ("Part 001" with triple spaces). Expected result: "Part 001".
If a lookup key has an extra leading space, the match can fail. TRIM can clean the lookup input before it is used.
=TRIM(C1)
// " SKU-X" -> "SKU-X"
=VLOOKUP(TRIM(C1), catalog, 2, FALSE)
In cell F4, use TRIM on C1 (" SKU-X" with a leading space) so it matches a lookup table correctly.
TRIM does not remove every kind of space. A common exception is the non-breaking space from copied web content. In that case, a pattern such as =TRIM(SUBSTITUTE(A1,CHAR(160)," ")) is more reliable.
TRIM removes extra spaces from text.=TRIM(text).Tell your friends about this post