Skip to content
getgriddy.ai/blog/how-to-use-len-function-in-excel
Excel

How to Use the LEN Function in Excel

LEN counts characters in Excel. Use it to audit invoice IDs, product codes, imported text, and fields that need a fixed length.

·5 min read

Reviewed by Griddy

Updated for current Excel and Google Sheets workflows, with examples chosen to map back to real spreadsheet tasks rather than abstract formula syntax.

LEN counts how many characters are in a cell. It counts letters, numbers, spaces, punctuation, and hidden extra spaces that are easy to miss by eye.

That makes it useful for checking IDs, cleaning imported data, validating codes, and finding text fields that are too long for a system upload.

The syntax

fx
=LEN(text)
  • text - the cell or text value you want to count

If A2 contains INV-1048, this formula returns 8:

fx
=LEN(A2)

Example: check invoice IDs before upload

Suppose invoice IDs must be exactly eight characters long. Column A contains the IDs you plan to upload.

Step 1. Count the characters

In B2, enter:

fx
=LEN(A2)

Fill the formula down the column.

Step 2. Flag the rows that need review

In C2, enter:

fx
=IF(LEN(A2)=8, "OK", "Check")

Rows marked Check may have missing digits, extra spaces, or a copied value that does not match the required format.

Step 3. Clean before counting if spaces are not meaningful

If leading or trailing spaces should not count, wrap the value in TRIM:

fx
=LEN(TRIM(A2))

That gives you the length of the cleaned value instead of the raw cell.

TIP

Use LEN(A2) and LEN(TRIM(A2)) side by side when you suspect hidden spaces. If the counts differ, the cell needs cleanup.

LEN counts spaces

This surprises people because spaces are hard to see. These two values are different to LEN:

Acme
Acme 

The second value has a trailing space, so LEN returns one extra character.

That matters when you are debugging failed lookups. Two customer names can look the same on screen while one carries a hidden trailing space from an export.

Common uses for LEN

Use caseFormula pattern
Check fixed-length IDs=LEN(A2)=8
Find values with hidden spaces=LEN(A2)-LEN(TRIM(A2))
Flag long notes=IF(LEN(A2)>250, "Too long", "OK")
Count cleaned text=LEN(TRIM(A2))

LEN vs counting words

LEN counts characters, not words. If a cell contains a sentence, LEN tells you how long the sentence is, including spaces and punctuation.

For most spreadsheet work, that is enough. Use it to validate text fields, not to analyze writing style.

The Griddy way

Length checks are easy for one column and annoying across a whole import.

"Flag invoice IDs that are not exactly eight characters and show which ones have hidden spaces"

Griddy can add the LEN checks, compare raw and cleaned values, and mark the rows that need review before the file goes into another system.

Skip the manual work

Describe it. Griddy does it.

Instead of writing this formula yourself, just tell Griddy what you need in plain English. Works in Excel and Google Sheets.