The TRIM, LEN, EXACT guide
Before you clean a column, find out what is wrong with it. Three tests cover most typed codes: A2<>TRIM(A2) for extra spaces, LEN(A2)<>7 for the wrong length, and NOT(EXACT(A2, UPPER(A2))) for small letters. Each returns TRUE for an entry that breaks the rule.
Mark first, fix later
A test that says "list the entries that break the rules" wants to see the bad rows, not a cleaned column. The same goes for a colleague who has to go back to the supplier and ask. A TRUE/FALSE column per rule does both: you can filter on it, count it with COUNTIF, and the original data stays as it was.
Extra spaces
TRIM(A2) is the text without spaces at the ends and with double spaces cut to one. If the cell is different from its trimmed version, it had extra spaces:
=A2<>TRIM(A2)
=LEN(A2)<>LEN(TRIM(A2)) gives the same answer. Neither finds a single space between words, because TRIM leaves those alone.
The wrong length
LEN(A2) counts every character, spaces included. A code that should be 7 long is wrong if it is longer or shorter, so test with <>:
=LEN(A2)<>7
>7 misses the short ones.
Capitals: why = doesn't work
Excel compares text without looking at capitals. ="brk-311"="BRK-311" is TRUE, so =A2<>UPPER(A2) is FALSE for every code, even the ones in small letters. EXACT compares character by character, capitals included:
=NOT(EXACT(A2, UPPER(A2)))
EXACT returns TRUE when the two are the same, so NOT turns it into "TRUE when something is in small letters". COUNTIF, MATCH, VLOOKUP and XLOOKUP ignore capitals too.
Then what?
=COUNTIF(B2:B11, TRUE)counts the entries with a problem.=OR(B2:D2)in a fourth column marks a row with any problem.- To fix the codes, a helper column with
=UPPER(TRIM(A2))covers spaces and capitals. The length needs a person to look.
The cleaning side is in the TRIM challenge.
FAQ
- How do I check if a cell has extra spaces in Excel?
- Compare it with its trimmed version: =A2<>TRIM(A2) returns TRUE when there are spaces at the ends or two in a row.
- Is Excel text comparison case-sensitive?
- No. ="abc"="ABC" is TRUE, and COUNTIF, MATCH and the lookups ignore capitals too. Use EXACT to compare with capitals.
- How do I find cells with lowercase letters in Excel?
- Use =NOT(EXACT(A2,UPPER(A2))). It is TRUE when the cell is different from its all-capitals version.
- How do I check the length of a cell?
- LEN(A2) returns the number of characters, spaces included. =LEN(A2)<>7 is TRUE when the cell isn't exactly 7 long.






























































