How to find values with the wrong number of characters in Excel
Formula (Excel and Google Sheets)
=IF(LEN(A2)=$E$1,"OK","Check")Compare the length with the expected one: =IF(LEN(A2)=$E$1,"OK","Check") flags every value that is too short or too long.
- Result on the example
- one result per row in
B2, filled down toB7 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.
How it works
LEN counts the characters, and comparing it with the expected length in E1 catches typos like a missing digit, an extra digit or an unexpected ZIP+4. Keeping the length in a cell lets you reuse the check for phone numbers, IDs or account codes.
=IF(LEN(A2)=$E$1,"OK","Check")Result"OK"
A2"55401"The value in A2.
LEN(A2)5LEN: Number of characters.- text
A2"55401"
- text
$E$15The value in E1.
LEN(A2)=$E$1TRUEThe = operator tests whether the two sides are equal.
IF(LEN(A2)=$E$1,"OK","Check")"OK"IF: Returns one value if a test is true, another if false.- logical_test
LEN(A2)=$E$1TRUE - value_if_true
"OK" - value_if_false
"Check"not used
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(LEN(A2)=$E$1,"OK","Check"). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =LEN(A2)<>$E$1 | FALSE, TRUE, TRUE…Different result | TRUE for the rows to fix, ready to filter or to use in conditional formatting. TRUE and FALSE instead of labels. |
Common mistakes
- ZIP codes stored as numbers lose leading zeros, so 02134 becomes 2134 and fails the check. Store them as text.
- Spaces count. Trim imported values before checking:
LEN(TRIM(A2)).
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Find values with the wrong number of characters
B2, show "OK" when the ZIP code has exactly the number of characters in E1, and "Check" otherwise. Fill down to B7.Questions
How do I count the values with the wrong length?
Use =SUMPRODUCT(--(LEN(A2:A7)<>$E$1)).
How do I stop wrong lengths being entered?
Use Data Validation > Text length, equal to 5.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.