The TRIM guide
=TRIM(A2) returns the text in A2 without spaces at the start or end, and with any run of spaces between words cut to one. "Leeds " and " Leeds" both become "Leeds", so counts and lookups stop missing them.
Why a space you can't see matters
To Excel, "Leeds " with a space at the end is a different value from "Leeds". COUNTIF(A2:A11, "Leeds") skips it, VLOOKUP returns #N/A for it, and a pivot table gives it a row of its own. Data typed into web forms, copied from emails or exported from other systems can carry these spaces.
The syntax
=TRIM(text)
TRIM removes spaces at both ends and turns two or more spaces between words into one. "Milton Keynes" with a double space becomes "Milton Keynes". It never removes the single space between words.
Clean first, then count
- Next to the messy column, write
=TRIM(A2)and fill it down. This is a helper column. - Point every count, total and lookup at the clean column:
=COUNTIF($B$2:$B$11, D2). - If you need the clean values in place of the old ones, copy the helper column and use Paste Special → Values over the original, then delete the helper.
The usual slip is step 2: the clean column is there, but the formulas still point at the old one.
How to spot hidden spaces
=LEN(A2)gives one more character than the word has.=A2=TRIM(A2)returns FALSE for a cell with extra spaces.- A count that comes out lower than the rows you can see is a hint.
When TRIM isn't enough
Text copied from web pages can contain a non-breaking space (character 160), which TRIM leaves alone. Turn it into a normal space first: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). CLEAN is a different tool: it removes characters that can't be printed, such as line breaks, not spaces.
Common mistakes
- Counting the old column. The helper column only helps if the formulas use it.
- SUBSTITUTE(A2, " ", "") instead of TRIM. It removes every space, so "Milton Keynes" becomes "MiltonKeynes".
- A range that slides. Lock the clean range as
$B$2:$B$11before filling the counts down.
The same problem inside a lookup is in the VLOOKUP #N/A mistake hunt.
FAQ
- How do I remove extra spaces in Excel?
- Use =TRIM(A2) in a helper column and fill it down. It removes spaces at the start and end and cuts doubles between words to one. Paste the results as values over the original if you need to.
- Why is COUNTIF not counting all my cells?
- Some cells probably have a space you can't see, so they don't match exactly. Clean the column with TRIM and count the clean column instead.
- Why doesn't TRIM remove all the spaces?
- TRIM keeps one space between words, and it doesn't touch non-breaking spaces (character 160) from web pages. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) for those.
- What is the difference between TRIM and CLEAN?
- TRIM removes extra spaces. CLEAN removes characters that can't be printed, such as line breaks. Some cleanups need both: =TRIM(CLEAN(A2)).
This task is in the timed data analyst and quick quiz practice tests. What Excel interview tests check






























































