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
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
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.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Member code | City | Length | |
| 2 | mara okafor | mara.okafor@example.com | GB-2041 | London | 14 |
| 3 | JONAS LIND | jonas.lind@example.org | SE-1187 | Malmö | |
| 4 | priya raman | priya.raman@example.net | IN-3302 | Pune | |
| 5 | Tomás Ruiz | tomas.ruiz@example.com | ES-0419 | Seville | |
| 6 | elif demir | elif.demir@example.org | TR-2750 | Izmir | |
| 7 | Kenji MORI | kenji.mori@example.net | JP-1093 | Osaka | |
| 8 | sofia rossi | sofia.rossi@example.com | IT-4468 | Turin | |
| 9 | Leo Brandt | leo.brandt@example.org | DE-3321 | Leipzig |
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. 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
| Argument | Required | What it is |
|---|---|---|
| text | Yes | The 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)=0when 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.