← All comparisons

TRIM vs CLEAN: the import-cleanup pair (and what both miss)

Pasted and imported text carries invisible junk that breaks lookups and duplicates 'identical' values. TRIM and CLEAN each remove a different kind — and the most common web-import culprit, the nonbreaking space, slips past BOTH.

The differences at a glance

TRIMCLEANSUBSTITUTECODE
RemovesLeading/trailing spaces + collapses internal runs to oneNonprintable control characters (codes 1-31)Whatever you tell it — the gap-fillerRemoves nothing — DIAGNOSES by revealing char codes
Nonbreaking space (CHAR(160))NOT removedNOT removedSUBSTITUTE(A2,CHAR(160)," ") converts itCODE(MID(...))=160 exposes it
In-cell line breaks (CHAR(10))KeptRemovedOr targeted: SUBSTITUTE(...,CHAR(10),", ")code 10
Typical sourceHuman typing, CSV paddingLegacy exports, database dumpsWeb pages, HTML copy-paste
CompatibilityUniversalUniversalUniversalUniversal — all verified by execution

Which should you use?

Compatibility (from executed tests)

All four execute identically in every version of all three apps we test. Diagnose before cleaning: LEN(A2)-LEN(TRIM(A2)) counts suspect spaces, and CODE(MID(A2,k,1)) at the failing position names the exact culprit — 160 means nonbreaking space, and only SUBSTITUTE will save you.

Example formulas

The full cleanup chain=TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," ")))
Why doesn't my lookup match?=CODE(MID(A2,LEN(A2),1))
Flatten line breaks readably=SUBSTITUTE(A2,CHAR(10),", ")

Full per-version details on each function page: TRIM · CLEAN · SUBSTITUTE · CODE.