LEN
Count the number of characters in a text string.
Spreadsheet editor
Spreadsheet editor
Syntax
=LEN(text)
Returns: Number Arguments
| Argument | Required | Description |
|---|---|---|
| text | Yes | The text string whose characters you want to count. Spaces count as characters. |
About
Use LEN whenever the length of an entry matters. It is handy for validating input (flagging phone numbers or codes that are too short), spotting extra spaces in imported data, and building dynamic formulas. LEN pairs well with LEFT, RIGHT, and MID when you need to pull part of a string by position, and with FIND or SEARCH to measure where one piece of text sits inside another.
A common trick combines LEN with SUBSTITUTE to count how often a character appears, such as counting words by counting spaces. If your text contains double-byte characters and you need bytes instead of characters, use LENB instead.
Exercises using LEN
Extract domain from email
IntermediateExtract the domain name (after @) from email addresses.
Open exerciseExtract file extension from a path
IntermediateExtract file extensions from shared-drive file paths when the number of characters after the dot changes from row to row.
Open exerciseExtract last name with RIGHT and LEN
IntermediateExtract last names from a customer list by combining RIGHT, LEN, and FIND.
Open exerciseComplex text parsing
AdvancedParse inconsistently formatted addresses into separate columns (street, city, state, zip).
Open exerciseExamples
Spaces and blank cells count
Spreadsheet editor
Count words with LEN and SUBSTITUTE
Spreadsheet editor
Watch out for
Forgetting that spaces count
LEN counts every space, including leading and trailing ones. A value that looks like 5 characters may return 6 or 7 because of spaces you cannot see.
→ Wrap the text in TRIM before measuring, for example =LEN(TRIM(A2)), so extra spaces do not throw off the count.
Measuring a number's value, not its display
LEN works on the underlying value, not the formatting. =LEN(A2) for a date or a currency amount counts the raw serial number or unrounded number, not what you see on screen.
→ Convert the number to text first with TEXT, such as =LEN(TEXT(A2,"mm/dd/yyyy")), so LEN counts the formatted result.
Counting bytes instead of characters
For most languages LEN is what you want, but with double-byte character sets it can give surprising results if you actually needed the byte count.
→ Use LENB when you need the number of bytes rather than the number of characters.