Confident CellsExcel practice Start free

LEFT, MID and RIGHT: taking part of a code or a postcode

Updated 26 November 2026 · 5 min read

LEFT takes characters from the start of some text, RIGHT from the end, and MID from the middle: with the code KT-2291-BLU in A2, =LEFT(A2,2) gives KT, =RIGHT(A2,3) gives BLU and =MID(A2,4,4) gives 2291. All three work in every version of Excel, on Windows and Mac and in Excel for the web. When the parts change length, FIND tells LEFT where to stop: =LEFT(A2,FIND(" ",A2)-1) gives everything before the space.

The formulas at a glance

You wantFormulaGives
The first few characters=LEFT(A2,2)KT from KT-2291-BLU
The last few characters=RIGHT(A2,3)BLU
Characters from the middle=MID(A2,4,4)2291 (start at the 4th, take 4)
Everything before a space=LEFT(A2,FIND(" ",A2)-1)LS6 from LS6 2QT
Everything after a character=RIGHT(A2,LEN(A2)-FIND("@",A2))acme.co.uk from an email address
How many characters=LEN(A2)11 for KT-2291-BLU
The part as a number=VALUE(MID(A2,4,4))2291, which adds up
The same, in Excel 365 and 2024=TEXTBEFORE(A2," "), =TEXTAFTER(A2,"@")No counting needed

Each one is worked through below, with a sheet.

A worked example: product codes

A shop's codes are made of three parts: a 2-letter department, a 4-digit product number and a 3-letter colour. To read KT-2291-BLU by hand:

  1. The department is the first 2 characters: KT.
  2. The colour is the last 3 characters: BLU.
  3. The product number starts at the 4th character (after K, T and the dash) and is 4 characters long: 2291.
ABCD
1CodeDeptProductColour
2KT-2291-BLUKT2291BLU
3GD-0418-GRNGD0418GRN
4BT-7730-REDBT7730RED
B2 holds =LEFT(A2,2), C2 holds =MID(A2,4,4) and D2 holds =RIGHT(A2,3).

The zero in GD-0418-GRN stays, because the result is text. That matters below, in "The result won't add up".

When the parts change length: FIND and LEN

UK postcodes have two parts with a space between. The second part is always 3 characters, so =RIGHT(A2,3) gets it. But the first part can be 2, 3 or 4 characters: M1, B33, LS6, SW1A. LEFT needs to know how many to take, so find the space first:

=LEFT(A2,FIND(" ",A2)-1)
  1. In LS6 2QT, the space is the 4th character, so FIND(" ",A2) gives 4.
  2. The part before it is 4 − 1 = 3 characters long.
  3. LEFT(A2,3) gives LS6.
ABCD
1PostcodeArea partLast partLength
2LS6 2QTLS62QT7
3M1 4BTM14BT6
4SW1A 9ZZSW1A9ZZ8
B2 holds =LEFT(A2,FIND(" ",A2)-1). D2 holds =LEN(A2), the number of characters.

LEN counts the characters, spaces included. Because the last part is always 3 characters after a space, =LEFT(A2,LEN(A2)-4) gives the first part too: LS6 2QT is 7 characters, and 7 − 4 = 3.

Everything after a character

An email address splits at the @. Before it is the person's name, after it is the company's domain. Take grace.reid@acme.co.uk:

  1. The @ is the 11th character, so FIND("@",A2) gives 11.
  2. The name is the 10 characters before it: =LEFT(A2,FIND("@",A2)-1) gives grace.reid.
  3. The whole address is 21 characters long. 21 − 11 = 10 characters come after the @, so =RIGHT(A2,LEN(A2)-FIND("@",A2)) gives acme.co.uk.
ABC
1EmailName partDomain
2grace.reid@acme.co.ukgrace.reidacme.co.uk
3t.fraser@northcol.ac.ukt.frasernorthcol.ac.uk
4priya@shahdesign.compriyashahdesign.com
B2 holds =LEFT(A2,FIND("@",A2)-1) and C2 holds =RIGHT(A2,LEN(A2)-FIND("@",A2)), both copied down.

MID does the same job with less arithmetic: start one after the @ and take plenty, =MID(A2,FIND("@",A2)+1,100). MID stops at the end of the text, so 100 is just "more than enough".

The same idea takes characters off the start or the end. =RIGHT(A2,LEN(A2)-3) takes the first 3 characters off, and =LEFT(A2,LEN(A2)-4) takes the last 4 off, so KT-2291-BLU becomes KT-2291.

A middle part of any length

Some product numbers have 5 digits, as in KT-22910-BLU. MID still starts at the 4th character, but now it needs to take 5. Every code has the same 2 letters, 2 dashes and 3-letter colour around the number, which is 7 characters, so the number is the length minus 7:

=MID(A2,4,LEN(A2)-7)
ABCD
1CodeLengthProductProduct (365)
2KT-2291-BLU1122912291
3KT-22910-BLU122291022910
4GD-418-GRN10418418
C2 holds =MID(A2,4,LEN(A2)-7) and D2 holds =TEXTBEFORE(TEXTAFTER(A2,"-"),"-"), both copied down. KT-22910-BLU is 12 characters, and 12 − 7 = 5.

Column D gets the same answers in Excel 365 by splitting at the dashes, as in the next section.

The easier way in Excel 365: TEXTBEFORE and TEXTAFTER

In Microsoft 365 and Excel 2024, you say what to split at, rather than counting characters:

They're not in Excel 2021 or older, which show #NAME? (see the #NAME? error). To split into several columns at once, see TEXTSPLIT. For names, splitting first and last names uses the same functions for first names, surnames, middle names and initials.

The result won't add up

LEFT, MID and RIGHT always give text, even when it looks like a number. So 2291 taken out of a code can't be added up, and won't match a real 2291 in a lookup. Wrap it in VALUE to turn it into a number:

ABC
1CodeMIDVALUE(MID)
2KT-2291-BLU22912291
3GD-0418-GRN0418418
4BT-7730-RED77307730
5Total010439
B2 holds =MID(A2,4,4) and C2 holds =VALUE(MID(A2,4,4)). SUM skips the text in column B, so B5 is 0; C5 adds up the numbers.

VALUE drops the leading zero, so 0418 becomes 418. If the zeros matter, as in a code you look up on another list, keep it as text and make sure the other list is text too. The TEXT function puts leading zeros back on a number.

Common mistakes

The space comes along too

=LEFT(A2,FIND(" ",A2)) includes the space, because FIND gives the space's own position. Take 1 off.

#VALUE! when there's nothing to find

If a postcode was typed with no space, such as LS62QT, FIND has nothing to find and gives #VALUE!. Wrap it to show a note instead: =IFERROR(LEFT(A2,FIND(" ",A2)-1),"No space"). FIND also cares about capitals, so FIND("x",A2) won't find an X; SEARCH does the same job and ignores capitals.

Spaces you can't see

A space at the start or end throws the counts out. Tidy the data with TRIM first.

Counting from the wrong place

MID's second part is where to start, counting the first character as 1. To start after the dash in KT-2291-BLU, that's character 4: K is 1, T is 2 and the dash is 3.

Try it now

Your turn

In B2, take the first part of the postcode in A2: everything before the space. The first parts are different lengths. Your formula will be copied down to B7.

AB
1PostcodeArea part
2LS6 2QT
3M1 4BT
4SW1A 9ZZ
5B33 8TH
6NE12 7XP
7G2 3DL

Open this in Try a formula: the same sheet with the answer filled in, to change or share by link.

Part of Excel data cleaning practice: every lesson on the topic, with a project in Excel.

Where it works

LEFT, MID, RIGHT, LEN and FIND work in every version of Excel on Windows and Mac, in Excel for the web and in Google Sheets. TEXTBEFORE and TEXTAFTER need Microsoft 365, Excel 2024 or Excel for the web.

Questions

How do I extract text after a character in Excel?

Find the character with FIND, then take everything after it. For the part after an @, use =MID(A2,FIND("@",A2)+1,100), which starts one character after the @ and takes up to 100. In Microsoft 365 or Excel 2024, =TEXTAFTER(A2,"@") does the same in one step. For the part before it, use =LEFT(A2,FIND("@",A2)-1) or TEXTBEFORE.

How do I remove the first or last characters from a cell?

Use LEN to count the characters, then take fewer. =RIGHT(A2,LEN(A2)-3) leaves off the first 3 characters, and =LEFT(A2,LEN(A2)-1) leaves off the last one. For KT-2291-BLU, =LEFT(A2,LEN(A2)-4) gives KT-2291. Copy the formula down, then paste the results back as values if you want to replace the original column.

Why won't the numbers from LEFT or MID add up?

LEFT, MID and RIGHT always give text, even when the result is all digits, so SUM skips them and lookups against real numbers fail. Wrap the formula in VALUE, as in =VALUE(MID(A2,4,4)), to get a number. VALUE drops any zeros at the front, so keep the text version for codes where 0418 and 418 must stay different.

What is the difference between FIND and SEARCH?

Both give the position of some text inside a cell, counting from 1. FIND cares about capitals, so FIND("a","ABC") gives #VALUE!. SEARCH ignores capitals and also lets you use wildcards such as * and ?. Either one works inside LEFT or MID to find a space, a dash or an @, where capitals make no difference.