Excel Practice
Lessons Lesson 54

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.

By the end you can

  • count the characters in a cell with LEN, spaces included.
  • use LEN to check a code is the right length.

Practises LEN TRIM

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.

Type a formula

How many characters are in the postcode in B2? Put the count in C2.

To begin, type it exactly:

=LEN(B2)

C2
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

  1. 1

    How many characters are in the postcode in B2? Put the count in C2. To begin, type it exactly: =LEN(B2).

    Hint. One argument, one cell.

  2. 2

    B3 was pasted in from another system and looks like a four-digit account number. Read =LEN(B3) and say what it returns.

    Hint. Look at where the text starts in the cell.

  3. 3

    Fields are limited to the number of characters in B8. In C6, say whether the reference in B5 is within the limit, TRUE or FALSE.

    Hint. Length, then a comparison against B8.

  4. 4

    B6 has nothing in it. Read =LEN(B6) and say what it returns.

    Hint. Nothing has a length too.