Count product code characters (LEN)
The problem
Problem statement
Shipping labels only fit a fixed number of characters, and every product code in A2:A5 is a different length — PRD-1023 is not the same width as SKU-9. Fill Code length in C2:C5 with how many characters each code contains. The dash counts.
LEN counts every character including the dash — case 3 is a different length, so don't hardcode 8.
Problem data
Show the sheet as a table (selectable, copyable)
| A | C | |
|---|---|---|
| 1 | Product code | Code length |
| 2 | PRD-1023 | |
| 3 | SKU-9 | |
| 4 | ACCESSORY-100 | |
| 5 | X |
Notes
LEN(text) returns the number of characters, including dashes, digits, and spaces. LEN("PRD-1023") is 8: three letters, one dash, and four digits. A hardcoded 8 fails as soon as the code in A2 changes.
How to approach
Your answer goes in C2:C5. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.
- Target cells are C2:C5 — start in C2, then fill down
- The text to measure is A2
LENtakes one argument: the text- Dashes and digits each count as one character
Official solutions
Show 2 solutions — try it yourself first
Approach 1: LEN of the product code
=LEN(A2)
Returns the character count of A2. PRD-1023 is 8 because the dash counts. Fill down through C5 so each code gets its own length.
Approach 2: LEN after TRIM
=LEN(TRIM(A2))
TRIM removes leading and trailing spaces, then LEN counts what remains. These sample codes have no extra spaces, so the result matches =LEN(A2). Use this when a pasted code might carry a stray space.
Function guide
FAQ
How do I count characters in a cell?
Use =LEN(A2). It returns the number of characters stored in A2. LEN("PRD-1023") is 8.
Does LEN count the dash and spaces?
Yes. Every character counts: letters, digits, dashes, and spaces. "SKU-9" is 5. "Ana Lee" is 7 because of the space.
What if the code has extra spaces?
A trailing space adds 1 to the count. =LEN(TRIM(A2)) removes leading and trailing spaces before measuring. Characters in the middle, including the dash, stay.