Data pasted from the web or other systems is full of stray spaces and invisible control characters that break lookups and totals. TRIM collapses extra spaces and CLEAN strips non-printing characters — together they scrub text spotless.
The example
Messy imported names cleaned to a tidy form.
| A | B | |
|---|---|---|
| 1 | Raw | Cleaned |
| 2 | Ann Lee | Ann Lee |
| 3 | Bo Ng | Bo Ng |
The formula
Strip spaces and hidden characters in one pass:
How it works
Each function tackles a different kind of junk:
TRIMremoves leading and trailing spaces and reduces any run of spaces between words to a single space.CLEANremoves non-printing characters (codes 0–31) — line breaks, tabs, and other control characters that sneak in from imports.- Nesting them —
TRIM(CLEAN(A2))— cleans hidden characters first, then collapses the spaces left behind. - Paste the result back as values to replace the messy originals once you’re happy.
TRIM doesn’t catch every space. The non-breaking space (CHAR(160), common in web copy) survives TRIM. Strip it first: =TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " "))).
Try it: interactive demo
Type text with extra spaces; see it cleaned.
Variations
Kill non-breaking spaces too
Handle CHAR(160) from web copy:
TRIM only
If there are no control characters:
Count spaces removed
How much junk there was:
Pitfalls & errors
Non-breaking spaces survive TRIM. CHAR(160) looks like a space but isn’t one to TRIM. SUBSTITUTE it to a normal space first.
TRIM keeps single internal spaces. It only collapses extra spaces — “New York” becomes “New York,” not “NewYork.”
CLEAN misses some modern characters. It removes codes 0–31 but not every invisible Unicode character; for stubborn cases, target the specific CHAR code with SUBSTITUTE.
Practice workbook
Frequently asked questions
How do I remove extra spaces in Excel?
Why does TRIM leave some spaces behind?
What's the difference between TRIM and CLEAN?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class