Extract a category code (LEFT)

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

Your inventory sheet packs everything into one product code like PRD-1023: the first three letters are the category, the rest is the serial. Before you can build a category filter, the report needs a separate Category code column. Fill C2:C5 from the codes in A2:A5.

The prefix is always three characters — case 2 switches to a service code, so nothing about PRD-1023 may be hardcoded.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
AC
1 Product codeCategory code
2 PRD-1023
3 PRD-2048
4 SRV-3011
5 ACC-5540

Notes

LEFT(text, n) returns the first n characters. The dash is character 4, so a 3-letter prefix stops right before it. If codes had variable prefix lengths, MID + SEARCH would be the more robust pattern.

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 cut from is A2
  3. You only need the first 3 characters
  4. LEFT takes two arguments: the text and the character count

Official solutions

Show 2 solutions — try it yourself first

Approach 1: LEFT with a fixed length

=LEFT(A2, 3)

Returns the first 3 characters of A2 — the category prefix. Fill down through C5 to classify the whole list.

Approach 2: LEFT up to the dash (robust)

=LEFT(A2, SEARCH("-", A2) - 1)

SEARCH finds the dash position; subtracting 1 keeps everything before it. This still works if prefixes are ever 2 or 4 letters long.

Function guide

Related practice

FAQ

How do I extract the first few characters of a cell?

Use =LEFT(A2, 3) to take the first 3 characters of A2. Replace 3 with however many characters your prefix needs.

What if prefixes have different lengths?

Stop at the delimiter instead: =LEFT(A2, SEARCH("-", A2) - 1) returns everything before the first dash, whatever its position.

Does LEFT change the original column?

No. It returns a new value in the formula cell; the source codes in column A stay untouched.