You ran TRIM but stray spaces remain — the culprit is the non-breaking space (CHAR 160) from web and PDF pastes. Substitute it for a normal space first, then TRIM and CLEAN.
The example
Web-pasted text with hidden spaces.
| A | B | |
|---|---|---|
| 1 | Raw | Clean |
| 2 | " Hello world " | Hello world |
The formula
The formula:
How it works
How it works:
- TRIM only removes CHAR(32) — the normal space. It ignores CHAR(160), the non-breaking space.
SUBSTITUTE(A2, CHAR(160), " ")turns non-breaking spaces into normal ones.CLEANstrips other non-printable control characters from imports.- Then
TRIMcollapses the now-normal extra spaces — the order matters.
This is the #1 “TRIM isn’t working” cause. Web pages and PDFs use CHAR(160) to prevent line breaks, and it survives TRIM and breaks lookups (“Acme Inc” ≠ “Acme Inc”). Always SUBSTITUTE(text, CHAR(160), " ") before TRIM when data came from a browser or PDF — it’s the fix for invisible mismatches.
Try it: interactive demo
Text with extra/odd spaces.
Variations
Just the substitution
Swap CHAR(160):
Remove all spaces
For a match key:
Find a hidden char
Its code:
Pitfalls & errors
TRIM can’t see CHAR(160). Substitute it first — TRIM only handles CHAR(32).
Order matters. Substitute → CLEAN → TRIM.
Other invisibles. CHAR(9) tabs, CHAR(13) returns — CLEAN catches most control characters.
Practice workbook
Frequently asked questions
Why doesn't TRIM remove all my spaces in Excel?
How do I fix lookups that fail on identical-looking text?
How do I find a hidden character?
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