Spreadsheet Practice

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 to B7
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"

  1. A2"55401"

    The value in A2.

  2. LEN(A2)5

    LEN: Number of characters.

    • textA2"55401"
  3. $E$15

    The value in E1.

  4. LEN(A2)=$E$1TRUE

    The = operator tests whether the two sides are equal.

  5. IF(LEN(A2)=$E$1,"OK","Check")"OK"

    IF: Returns one value if a test is true, another if false.

    • logical_testLEN(A2)=$E$1TRUE
    • value_if_true"OK"
    • value_if_false"Check"not used

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.

FormulaResultWhen to use it
=LEN(A2)<>$E$1FALSE, TRUE, TRUE…Different resultTRUE 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

In 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.