Excel Supreme

Excel track · Exercise 49 of 86 Paid

LEFT + FIND: pull out a prefix

Pull a prefix of any length out of a code with LEFT and FIND.

Advanced

Order log

Read-only data · answer in B6

In B6, extract the three-letter prefix from the reference in B2 (everything before the first dash).

ABC
1OrderReferenceCustomer
2SO-1ORD-2024-0917Ana
3SO-2INV-2024-0612Bo
4SO-3ORD-2023-1180Cy
5
6Prefix for SO-1

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

B6

What it does

FIND reports where a character sits inside a string, and LEFT takes a given number of characters from the start. Joined, they cut a prefix of any length off a code. The reference in B2 is ORD-2024-0917, so FIND("-",B2) returns 4, counting from one.

The dash is not part of the prefix, so the length is 4 minus 1. The formula =LEFT(B2,FIND("-",B2)-1) returns ORD in B6, and the minus one is the only thing keeping the dash out. Type the position FIND gave you and the answer comes back as ORD-.

LEFT(B2,3) gives the same answer on every row of this sheet, which is why it feels safe. It breaks the first time a code arrives with a four-letter prefix. FIND keeps the formula tied to the dash instead.

Syntax

=LEFT(text, FIND(delimiter, text) - 1)

Worked example

On Order log, =LEFT(B2,FIND("-",B2)-1) returns ORD.

=LEFT(B2,FIND("-",B2)-1)

Common errors

Error codes for LEFT and FIND
ErrorWhat it means and how to fix it
#VALUE!The search string is absent from the cell, and FIND raises #VALUE! rather than returning 0.
Off by oneLEFT(B2,FIND("-",B2)) keeps the dash, so the answer reads ORD- instead of ORD.
No FINDLEFT(B2,3) answers ORD here and drops the first letter of a four-letter prefix.

At work

Reference ids, ticket keys and SKU families: LEFT and FIND pull a coded prefix out without a helper column.