Count product code characters (LEN)

Easy Text
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

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)
The exercise data, as a table
AC
1 Product codeCode 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.

  1. Target cells are C2:C5 — start in C2, then fill down
  2. The text to measure is A2
  3. LEN takes one argument: the text
  4. 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

Related practice

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.