1TRIM
=TRIM(A2)
- In B2 type =TRIM(A2) and press Enter.
- Fill down. Leading and trailing spaces go, and repeated spaces between words become one.
- To replace the original, copy the results and paste over them with Paste Special > Values.
Clean leading, trailing and repeated spaces with TRIM, and handle the non-breaking spaces that TRIM misses with SUBSTITUTE.
Imported text often carries invisible spaces: a gap before a name, two spaces between words, a trailing space after the last letter. They look harmless, but they break lookups, because "Alpha" and "Alpha " are different values, and they make duplicates hard to spot.
TRIM removes every leading and trailing space and reduces runs of spaces between words to one:
=TRIM(A2)
It is the first step when a lookup fails for no visible reason.
TRIM only handles the ordinary space, character 32. Text copied from web pages and PDFs often contains non-breaking spaces, character 160, which look the same but which TRIM leaves alone. Replace them with ordinary spaces first, then trim:
=TRIM(SUBSTITUTE(C2, CHAR(160), " "))
If a cell still looks off after that, other invisible characters may be present. CLEAN removes the non-printing control characters, such as line breaks from copied text, and can wrap TRIM: =TRIM(CLEAN(A2)).
Do not use SUBSTITUTE to delete every space unless you really mean to. That would squash the words together.
The ribbon alternative is Find and Replace: press Ctrl+H, type two spaces in Find what and one space in Replace with, and choose Replace All, repeating until nothing changes. It edits the data in place and does not remove leading or trailing spaces on its own, so the formula route is more thorough. The Logic and text track has a lesson on cleaning data.
=TRIM(A2)
=TRIM(SUBSTITUTE(C2,CHAR(160)," "))
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In B2, remove the leading, trailing and repeated spaces from A2. Fill down to B7.
Answer in B2, then it fills down to B7.
Logic and text covers this in lesson 7, TRIM and CLEAN.