Text function
Excel TRIM function
TRIM removes spaces from the start and end of text and shrinks any run of spaces between words down to one. It is the first thing to try when a lookup fails on data pasted from another system.
=TRIM(text)Arguments
text- The text or cell to clean up.
TRIM examples
Every result below was calculated from this sample sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | |
|---|---|---|---|
| 1 | Imported name | Code | Price |
| 2 | Olivia Brown | K-220 | 18 |
| 3 | Ethan Clark | K-310 | 42 |
| 4 | Zoe Martin | K-415 | 27 |
Result: Olivia Brown
Removes the leading, trailing and double spaces: "Olivia Brown".
Result: 5
Shows how many extra spaces were hiding in the cell: 5.
Result: FALSE
FALSE: the original code has a hidden trailing space, so it differs from its trimmed version.
Result: TRUE
Trim first and the match works: TRUE.
How to use TRIM
- Insert a helper column next to the messy data.
- Type =TRIM( and select the first cell.
- Close the bracket and fill down.
- Copy the column and Paste Values over the original.
Common TRIM mistakes
Non-breaking spaces from web pages
TRIM only removes normal spaces (code 32). Replace character 160 first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
Expecting single spaces between words to go
TRIM keeps one space between words. To remove all spaces use SUBSTITUTE(A2," ","").
Line breaks remain
TRIM does not remove line breaks. Use CLEAN as well: =TRIM(CLEAN(A2)).
TRIM FAQ
Why is TRIM not removing spaces in Excel?
The spaces are probably non-breaking spaces (CHAR(160)) from a web page. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).
How do I remove trailing spaces in Excel?
Use =TRIM(A2) in a helper column, then paste the results as values over the original.
Why does my VLOOKUP fail when the values look the same?
Often one side has a hidden trailing space. Wrap the lookup value in TRIM, or clean the table column with TRIM first.
Practice TRIM in these lessons
Guides that use TRIM
- How to remove duplicates in Excel
- How to combine first and last name in Excel
- How to separate first and last name in Excel
- How to remove spaces in Excel
- How to find duplicates in Excel
- How to compare two columns in Excel
- How to capitalize the first letter in Excel
- #N/A error in Excel: causes and fixes
Related functions
Updated