How to Use TRIM in Excel to Remove Extra Spaces
Use the
TRIM function in Excel to remove all extra spaces from text except for single spaces between words. Enter =TRIM(A1) to clean the text in cell A1 by removing leading, trailing, and multiple spaces.Syntax
The TRIM function has a simple syntax with one argument:
TRIM(text): text is the cell or text string you want to clean.
This function removes all spaces from the text except for single spaces between words.
excel
=TRIM(text)
Example
This example shows how TRIM removes extra spaces from a text string in cell A1.
excel
A1: " Hello world! "
B1: =TRIM(A1)Output
B1: "Hello world!"
Common Pitfalls
People often expect TRIM to remove non-breaking spaces or other invisible characters, but it only removes regular spaces (ASCII 32). Also, TRIM does not remove spaces inside words, only extra spaces between words.
Right: =TRIM(SUBSTITUTE(A1, CHAR(160), " ")) is needed if your text has non-breaking spaces.
Use TRIM alone only for normal spaces.
Quick Reference
| Function | Purpose | Example |
|---|---|---|
| TRIM(text) | Removes extra spaces except single spaces between words | =TRIM(A1) |
| SUBSTITUTE(text, CHAR(160), " ") | Replaces non-breaking spaces with normal spaces | =SUBSTITUTE(A1, CHAR(160), " ") |
| TRIM(SUBSTITUTE(text, CHAR(160), " ")) | Removes extra spaces including non-breaking spaces | =TRIM(SUBSTITUTE(A1, CHAR(160), " ")) |
Key Takeaways
Use =TRIM(cell) to remove extra spaces except single spaces between words.
TRIM removes leading, trailing, and multiple spaces inside text.
TRIM does not remove non-breaking spaces; use SUBSTITUTE with CHAR(160) for those.
TRIM keeps single spaces between words intact.
Always check your data for special space characters if TRIM alone doesn't clean text.