LEN: Counting Characters
About this lesson
LEN returns the number of characters in a piece of text. It counts spaces and punctuation the same as letters.
- count the characters in a cell with LEN, spaces included.
- use LEN to check a code is the right length.
The idea
One argument, one number back. Give it a postcode of eight characters and it returns 8. The space in the middle is one of them.
What makes it useful is what it finds. A value pasted in from another system often arrives with spaces in front of it or behind it. Nothing on screen shows them. That value is not equal to the one you typed. So a lookup returns #N/A and a comparison returns FALSE. The cell looks completely normal while you check the formula again and again. LEN is the two-second test. If the count is larger than what you can see, the difference is spaces. Do that before you debug anything else about text that will not match.
The mistake to watch for
Trusting what a cell looks like. A value pasted from another system arrives with spaces in front of it or behind it. Nothing on screen shows them. The value no longer equals the one you typed. The lookup returns #N/A and the comparison returns FALSE. Run LEN over text that will not match before you check anything else. A count larger than what you can see is the answer.
Where this comes up again
This lesson needs JavaScript to run. Everything below is the lesson in full, but you cannot type into the grid or be marked.
How many characters are in the postcode in B2? Put the count in C2.
To begin, type it exactly:
=LEN(B2)
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Field | Entry | Length | ||||
| 2 | Postcode | SW1A 2AA | |||||
| 3 | Account | 4471 | |||||
| 4 | Surname | Okonkwo | |||||
| 5 | Reference | GB-2024-0031 | |||||
| 6 | Note | ||||||
| 7 | |||||||
| 8 | Field limit | 10 |
Every step
-
How many characters are in the postcode in
B2? Put the count inC2. To begin, type it exactly:=LEN(B2). -
B3was pasted in from another system and looks like a four-digit account number. Read=LEN(B3)and say what it returns. -
Fields are limited to the number of characters in
B8. InC6, say whether the reference inB5is within the limit,TRUEorFALSE. -
B6has nothing in it. Read=LEN(B6)and say what it returns.