Imported text fails later formulas when the extra characters are still in the cell. TRIM, CLEAN, and SUBSTITUTE remove different characters. How to split first and last names in Excel already uses the padded Maria Lopez cell, and it says a nonbreaking space, character 160, survives TRIM.
Ordinary spaces collapse to one
TRIM of Maria Lopez is Maria Lopez. The leading spaces go away, the trailing spaces go away, and the two spaces between the names become one.
=TRIM(" Maria Lopez ")| A | B | |
|---|---|---|
| 1 | Raw | Clean |
| 2 | Maria Lopez | Maria Lopez |
=TRIM(" Maria Lopez ")
That is the name the split page starts from after TRIM. TEXTBEFORE of the raw cell, before TRIM, is blank, because the first character is a space. Clean the cell before you split it.
TRIM does not remove character 160. A name that looks padded and does not change is often that character. SUBSTITUTE of CHAR(160) with an ordinary space, then TRIM, is the fix:
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))
A line break becomes no space at all
CLEAN removes characters 0 through 31. A line break is character 10. Austin, a line break, and TX become AustinTX. CLEAN does not insert a space where the line break was.
=CLEAN("Austin"&CHAR(10)&"TX")| A | B | |
|---|---|---|
| 1 | Raw | Clean |
| 2 | Austin, then a line break, then TX | AustinTX |
=CLEAN("Austin"&CHAR(10)&"TX")
CLEAN also leaves character 160 in place, and it leaves ordinary spaces in place. The CLEAN page says both. If the words should stay apart, the space has to be in the text you keep. SUBSTITUTE of the line break with a space does that. CLEAN will not.
Collapse space does the 160 and the TRIM
xl.collapse.space substitutes character 160 with an ordinary space, then TRIM. Two spaces, the word Austin, and two spaces become Austin.
=xl.collapse.space(" Austin ")| A | B | |
|---|---|---|
| 1 | Raw | Clean |
| 2 | Austin | Austin |
=xl.collapse.space(" Austin ")
=TRIM(SUBSTITUTE(" Austin ",CHAR(160)," "))
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME?. The TRIM of SUBSTITUTE above is the same two steps without the name. It does not run CLEAN. A line break still needs CLEAN, or a SUBSTITUTE of CHAR(10), before the spaces are collapsed.
The nested order on the CLEAN page is TRIM of a CLEAN of a SUBSTITUTE. SUBSTITUTE handles 160. CLEAN handles the line break. TRIM handles the ordinary spaces. Each one leaves the characters the others own.