Example 1
Count the characters in a code
C2 =LEN(A2)
Result: 7
Seven characters: FX, a dash, and four digits.
C2 =LEN(A2) returns 7
Returns the number of characters in a piece of text, spaces included.
Syntax
=LEN()
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =LEN(A2) returns 7
LEN returns the number of characters in text. Spaces, punctuation and line breaks all count. It is a small function that earns its place in checks and in other text formulas.
=LEN("Nitrile gloves") returns 14: 13 letters and one space. Every character counts, including spaces at the start and end, which you can't see in the cell. An empty cell returns 0.
LEN measures the stored value, not what the cell displays. A cell holding the number 1234.5 formatted as $1,234.50 has a LEN of 6, the length of 1234.5. A date such as 15-Mar-2025 is stored as the serial 45731, so LEN returns 5. If you want the length of the displayed text, measure it through TEXT: =LEN(TEXT(B2,"dd-mmm-yyyy")) returns 11.
Validating a code. Many IDs have a fixed length. =IF(LEN(A2)=8,"OK","Check length") flags codes that are too short or too long, for instance because a leading zero was lost.
Spotting hidden spaces. If a lookup fails even though two cells look identical, compare the lengths. =LEN(A2)-LEN(TRIM(A2)) returns the number of extra spaces that TRIM would remove. Anything above 0 means the cell has leading, trailing or doubled spaces.
Counting a character. Remove the character with SUBSTITUTE and see how much shorter the text becomes: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) counts the commas in A2. For a word count, count the spaces and add one: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1. Use this one on text that isn't empty, because it returns 1 for an empty cell.
Working with LEFT, RIGHT and MID. LEN gives you the length that these functions need when you want to keep or drop a fixed number of characters at one end: =LEFT(A2,LEN(A2)-4) removes the last four characters, and =RIGHT(A2,LEN(A2)-FIND(".",A2)) takes everything after the first dot.
Excel also has LENB, which counts bytes for double-byte languages. It matches LEN unless a double-byte language is your default, so use LEN.
A cell can hold at most 32,767 characters, and Excel displays only the first 1,024 of them in the cell itself. LEN measures the full length, which makes it useful to check whether imported text was cut off at a system's own limit, such as 255 characters.
In Microsoft 365, LEN accepts a range and returns an array: =LEN(A2:A9) spills the length of each cell. Wrap it in SUM to total the characters, or in MAX to find the longest entry: =MAX(LEN(A2:A9)).
A2. Numbers are measured as the text they would show in a General-format cell, and an empty cell has length 0.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
C2 =LEN(A2)
Result: 7
Seven characters: FX, a dash, and four digits.
C2 =LEN(A2) returns 7
Example 2
C3 =IF(LEN(A3)=8,"OK","Check length")
Result: Check length
FIN-305 has 7 characters because a leading zero was lost. The same formula in C2 returns OK.
C3 =IF(LEN(A3)=8,"OK","Check length") returns Check length
Example 3
B2 =LEN(A2)-LEN(SUBSTITUTE(A2,",",""))
Result: 3
The text is 23 characters long and 20 without the commas, so there are 3 commas. That means 4 tags.
B2 =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) returns 3
Example 4
B2 =LEN(A2)-LEN(TRIM(A2))
Result: 4
The cell has 17 characters. TRIM leaves "Anya Kowalski" with 13. The difference is two leading spaces, one extra space in the middle and one trailing space.
B2 =LEN(A2)-LEN(TRIM(A2)) returns 4
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In B2, return the number of characters in the tags in A2.
Answer in B2.
LEN(TRIM(A2)) when a lookup or match fails for no visible reason.LEN(TEXT(B2,"dd-mmm-yyyy")) to measure the display text.$1,234.50 has a LEN of 6, not 9, because LEN sees 1234.5.LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 returns 1 for an empty cell. Wrap it in an IF that returns 0 when LEN(TRIM(A2))=0.CHAR(10) between them, so LEN is one higher than the count of visible characters. CLEAN removes it.Use `=LEN(A2)`. It counts every character in the cell, including spaces and punctuation.
Subtract the length without that character from the full length: `=LEN(A2)-LEN(SUBSTITUTE(A2,",",""))`. Change the comma to the character you want. SUBSTITUTE is case-sensitive, so "a" and "A" are counted separately.
The cell has hidden spaces, a line break or another non-printing character. Use TRIM to remove extra spaces and CLEAN to remove non-printing characters, and compare lengths to confirm.
Yes. Every space counts, at the start, between words and at the end. TRIM removes the extra ones before you measure.
In Microsoft 365, use `=MAX(LEN(A2:A20))`. In older versions, use `=MAX(INDEX(LEN(A2:A20),0))`, or enter the first formula with Ctrl+Shift+Enter.
LEN is taught in Logic and text, lesson 7: TRIM and CLEAN. Each lesson is a short, graded exercise like the one above.