What TRIM does
TRIM removes extra spaces from text. It deletes every space at the start and the end, and where words are separated by two or more spaces it leaves just one, so ” Ana Silva ” becomes “Ana Silva”. Single spaces between words stay.
Extra spaces are invisible, which is why they cause so much trouble. Data exported from other systems or copied from emails often carries them, and to Excel “S-118 ” with a trailing space is a different value from “S-118”. Lookups return #N/A and COUNTIF misses rows, so TRIM is usually the first step in cleaning a column. To check a cell for hidden spaces, measure it with LEN: the trailing space makes “S-118 ” six characters long instead of five.
Syntax
textRequired- The text to clean, usually a cell such as
A2. TRIM removes spaces at the start and end, and turns runs of spaces between words into one.
Example: clean a column of imported names
The names came from another system with stray spaces. The formula in B2 is filled down to B5.
Once the cleaned column is checked, copy it and paste it over the original as values, so the clean names stay when the formulas are deleted.
Example: a lookup that works despite a stray space
A staff number was pasted into B7 with a space after it, so a plain lookup finds nothing. TRIM the lookup value first:
Common mistakes
- Text copied from a website often contains non-breaking spaces, which TRIM doesn’t remove. Swap them for ordinary spaces first:
=TRIM(SUBSTITUTE(A2,CHAR(160)," ")). - If the table has the extra spaces, trimming the lookup value doesn’t help. Clean the table’s column too.
- The cleaned names depend on the original column, and deleting that column turns them into
#REF!. Paste the results as values before you tidy up. - Line breaks and other non-printing characters stay after TRIM. CLEAN removes those, and the two are often used together:
=TRIM(CLEAN(A2)).
Frequently asked questions
Does TRIM remove the spaces between words?
It keeps one space between words and removes any extra ones. To remove every space, use =SUBSTITUTE(A2," ","").
Why is TRIM not working?
The space it leaves is most likely a non-breaking space, character 160, which web pages use and TRIM doesn’t touch. Swap it for an ordinary space first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
How do I trim a whole column in place?
Put TRIM in a helper column, fill it down, copy the results, and paste them over the original column as values. Then delete the helper column.
Does TRIM change numbers?
TRIM returns text, so a number with spaces around it comes back as text. Wrap it in VALUE when you need the number: =VALUE(TRIM(A2)).