Text
Counting characters in a code
Definition
Counting characters in a code means giving LEN the cell that holds the code, including any hyphen.
Syntax
=LEN(text)
Arguments
| Argument | Meaning |
|---|---|
text |
The cell that holds the code to measure. |
Worked example
A stock list stores short lot codes in B2:B4.
| A: Bin | B: Code |
|---|---|
| 1 | Q-12 |
| 2 | M-8 |
| 3 | R-40 |
Formula: =LEN(B2)
Result: 4. Q-12 has four characters, and the hyphen counts as one of them.
Practice
Cell A2 holds AB-19. In B2, write a formula that returns the length of A2.
- In B2, write a LEN formula for A2.
- B2 should show the length of A2.
Step 1 of 2
Enter =LEN(A2) in B2.
A2 is AB-19, including the hyphen, so the length is 5.
Formulas here use English function names, such as SUM, and a period as the decimal separator, in every language.
Loading the sheet…
B2 uses LEN.
B2 now shows 5.
The next lesson is Adding two separate ranges.
Related functions
LEN is the function that counts every character in that code.
Common mistake
Subtracting the hyphen by hand, as in =LEN(B2)-1: that returns 3, but the hyphen is a real character, so the length is 4.