LEN in Excel: how to use it
LEN counts how many characters a cell contains, spaces and punctuation included.
Try the first exercises for freeIn the lesson LEN and TRIM
What does LEN do?
LEN counts how many characters there are in a cell: letters, digits, spaces and punctuation. You get one number back.
On its own that doesn't seem very useful, but LEN helps you track down mistakes: a code that's too short, a hidden space, or a text that's too long for a field. Together with LEFT, RIGHT and MID, you can also cut out pieces of varying length.
When do you use LEN?
- Checking that every branch code has four characters: =IF(LEN(A2)=4,"OK","Check").
- Tracking down a hidden space: =LEN(A2)-LEN(TRIM(A2)).
- Checking that a text isn't too long, such as a text message: =LEN(B2)<=160.
- Everything except the first three characters: =RIGHT(A2,LEN(A2)-3).
Syntax
The syntax is the fixed pattern of a function. The words in the brackets are placeholders: that's where you fill something in yourself, such as a cell, a number or a piece of text. Everything else you type exactly as it is.
Filled in: =LEN(A2)
This is how to read the formula, part by part:
| Part | What it means | In the example |
|---|---|---|
= | Every formula starts with an equals sign. Without =, Excel treats what you type as ordinary text. | = |
LEN | The name of the function: that's how Excel knows what to do. You can type it in lower case, Excel puts it in capitals itself. | LEN |
( ) | Straight after the name come the brackets. Inside them is what the function needs to work: the arguments. | ( ) |
text | The cell or text whose characters you count. | A2 |
LEN step by step
C1 contains =LEN(A2). U, K, a hyphen, four digits, another hyphen and two digits: 10 characters in all. Change the numbers or the formula and see what happens.
This is how to build the formula yourself:
- Click C1 and type LEN with a bracket.
=LEN( - Click the cell with the text, A2.
=LEN(A2 - Close the bracket and press Enter: the code has 10 characters, including the hyphens.
=LEN(A2)
More examples
Checking a code
B2 contains =IF(LEN(A2)=4,"OK","Check"). This branch code has five characters instead of four. Type 9000 in A2, and you see OK.
Everything except the start
C1 contains =RIGHT(A2,LEN(A2)-3). LEN gives 10. Take away the 3 characters of UK-, and RIGHT takes the 7 characters that are left.
Spaces count too
C1 contains =LEN(A2). Mark Hall has 9 characters, but the cell gives 10: there's another space at the end.
Tracking down hidden spaces
Two names look the same, but VLOOKUP can't find them? Compare their length. =LEN(A2)-LEN(TRIM(A2)) shows how many extra spaces a cell contains.
Checking whether a code is right
A customer number often has a fixed length. =IF(LEN(A2)=8,"OK","Check") shows straight away which numbers don't have eight characters.
Where it often goes wrong
- LEN also counts the characters of a number: =LEN(1500) gives 4. Formatting, such as a thousands separator, doesn't count.
- An empty cell gives 0, a cell with just a space gives 1.
Practise this in the lesson LEN and TRIM. The first exercises are free.
Frequently asked questions
How do I count the words in a cell?
=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 counts the spaces between the words and adds 1.
Read next
LEFT, RIGHT and MIDTRIMUPPER, LOWER and PROPERSEARCH and FINDJoining text