Highlight Cells by Text Length

Excel Formulas › Conditional Formatting

All versionsLEN

Catch entries that are too long or too short — a code that should be 5 characters, a tweet over the limit. A LEN rule flags cells whose length is off.


Quick formula: flag entries not exactly 5 characters:
=LEN(A1) <> 5
LEN counts the characters; <> 5 highlights anything that isn’t the required length.

Functions used (tap for the full reference guide):

The example

Codes that aren’t 5 characters are flagged.

AB
1CodeLength
2AB1235
3AB124

The formula

Flag the wrong lengths:

=LEN(A1) <> 5 // not exactly 5 characters

How it works

LEN measures, the comparison flags:

  1. LEN(cell) returns the number of characters (spaces included).
  2. Compare it: <> 5 for “wrong length,” > 100 for too long, < 3 for too short.
  3. Apply as a CF rule so problem entries jump out for cleanup.
  4. Pair with TRIM in the test — =LEN(TRIM(A1))<>5 — if stray spaces shouldn’t count toward the length.

Prevent it on entry with Data Validation → Text length. CF highlights existing wrong-length data; validation stops new bad entries — see the restrict-input-length recipe.

Try it: interactive demo

Live demo

Required length, then entries.

Variations

Too long only

Over a limit:

=LEN(A1) > 100

Ignore spaces

Trim first:

=LEN(TRIM(A1)) <> 5

Block on entry

Data Validation → Text length.

Pitfalls & errors

Spaces count. LEN includes trailing spaces — “ABC ” is length 4. Use TRIM if that’s not intended.

Numbers vs text length. LEN counts the displayed digits of a number, which can surprise with decimals or formatting.

Match the relative ref to the active cell.

Practice workbook

📊
Download the free Highlight Cells by Text Length practice workbook
A text-length CF rule with the too-long and trim variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I highlight cells that are the wrong length in Excel?
Add a formula CF rule =LEN(A1) <> 5 (or your required length). LEN counts characters and the comparison flags the wrong ones.
How do I ignore trailing spaces?
Wrap with TRIM: =LEN(TRIM(A1)) <> 5.
How do I stop wrong-length entries being typed?
Use Data Validation → Text length to block them on input; CF audits existing data.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Restrict input length · Remove extra spaces · Highlight with a formula

Function references: LEN