formulastreak

Text function

LEN function in Google Sheets and Excel

LEN counts the characters in a text, including spaces, punctuation and digits.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

LEN(text)

Arguments in [brackets] are optional. Google Sheets writes it LEN(text).

Example

=LEN(A2) reads: Count every character in A2 (" mara okafor "), spaces included.

Workshop sign-ups · edit E2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultE2 = 14
ABCDE
1NameEmailMember codeCityLength
2 mara okafor mara.okafor@example.comGB-2041London14
3JONAS LINDjonas.lind@example.orgSE-1187Malmö
4priya ramanpriya.raman@example.netIN-3302Pune
5Tomás Ruiz tomas.ruiz@example.comES-0419Seville
6elif demirelif.demir@example.orgTR-2750Izmir
7 Kenji MORIkenji.mori@example.netJP-1093Osaka
8sofia rossisofia.rossi@example.comIT-4468Turin
9Leo Brandtleo.brandt@example.orgDE-3321Leipzig

E2 shows 14: “ mara okafor ” has 11 letters and spaces between them, plus 3 stray spaces.

How the spreadsheet calculates it

Counts the characters in A2, spaces included.

  1. 1. LEN: Counts the characters in A2, spaces included.
    • text = `A2`: the cell to measure

More LEN examples

  • =LEN(TRIM(A2))The length without stray spaces: 11 for mara okafor.
  • =LEN(A2)-LEN(TRIM(A2))How many extra spaces A2 holds.
  • =LEN(B2)-LEN(SUBSTITUTE(B2,".",""))How many dots the email has.
  • =IF(LEN(C2)=7,"OK","Check code")Flags member codes of the wrong length.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Compare LEN before and after TRIM or CLEAN to see what a cleanup removed.
  • Use LEN minus a FIND position to count characters after a separator.
  • Combine with IF to flag entries that are too long or too short.

What LEN is used for

Finding stray spaces, checking that codes, IDs and phone numbers have the right length, validating text limits (a 160-character description), and working out positions for RIGHT and MID.

Arguments

ArgumentRequiredWhat it is
textYesThe text or cell to measure, such as A2. A number is measured by its digits, not its formatting: a price shown as $34.00 is the number 34, so LEN gives 2.

Common mistakes

  • Forgetting that spaces count, including the ones you can't see.

  • Testing for an empty cell with LEN(A2)=0 when it might hold a space: that's FALSE for a single space. Trim first: LEN(TRIM(A2))=0.

  • Expecting LEN to count words: it counts characters. Count the spaces instead (see the question below).

In Google Sheets

Google Sheets has LEN(text) with the same single argument.

Errors you may see with LEN

  • #VALUE!: The cell it measures shows #VALUE! (or another error); LEN passes the error on.

Questions

How do I count the words in a cell?

Count the spaces between words and add 1: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1. TRIM makes sure each gap is one space.

How do I count how many times a character appears?

Remove it and compare the lengths: =LEN(B2)-LEN(SUBSTITUTE(B2,".","")) counts the dots in B2; mara.okafor@example.com has 2.

How do I check that a code has the right length?

Compare LEN with the length it should be: =LEN(C2)=7 is TRUE for GB-2041 and FALSE for a code with a digit missing.

Why is LEN bigger than the text looks?

Something invisible is in the cell: stray spaces, a non-breaking space or a line break. Compare LEN(A2) with LEN(TRIM(A2)) and LEN(CLEAN(A2)) to see which.

Does LEN count the decimals a cell shows?

It counts the value's own characters, not the format: 34 formatted as $34.00 has a LEN of 2. To measure what people see, measure the formatted text instead: LEN(TEXT(G2,"$#,##0.00")) is 6.

Sources

Official documentation the facts on this page were checked against.

Practise LEN on a live sheet

Lesson 24, Find a position: FIND and LEN (Unit 6, Text and dates), has 4 graded exercises, checked instantly, with steps and hints when you're stuck. Pro