Skip to content

Take part of a text with LEFT, RIGHT and MID

Text functions7 min

Builds on Decide with IF.

Order numbers and product codes often pack several facts into one cell. When finance asks for the country of every order, or the warehouse wants stock counted by color, the answer is already inside the code.

How it works

Excel treats text as a row of characters, numbered from 1 on the left. Every character counts, spaces and dashes included. In the asset tag LT-2024-0587, L is character 1, the first dash is character 3, and the year runs from character 4 to character 7.

Three functions copy characters out of that row. Each one takes the text, usually a cell, and how many characters you want:

RowABC
1FunctionTakes characters fromArguments
2LEFTthe startthe text, how many
3RIGHTthe endthe text, how many
4MIDany positionthe text, where to start, how many

They suit codes with a fixed layout, where the part you want sits at the same position on every row. RIGHT also copes with codes of different lengths when the part you want always comes last, because it counts back from the end.

The result is always text, even when it looks like a number. That's why 0587 keeps its leading zero.

Example

IT keeps a register of laptops, one asset tag each. The tag in F2 is LT-2024-0587: the type, the year bought and a serial number.

=MID(F2,4,4)
Takes 4 characters from the tag in F2, starting at character 4.

It returns 2024. =LEFT(F2,2) returns LT, and =RIGHT(F2,4) returns 0587.

Common mistakes

  • =MID(F2,3,4) returns -202. The start is the position of the first character you want, counting from 1 and counting the dashes.
  • A fixed count breaks when the first part changes length: for a desk tagged DSK-2023-0112, =LEFT(F5,2) returns DS. The next lesson finds the dash with FIND, so the count can change from row to row.
  • 0587 from RIGHT is text, so it sits on the left of the cell and SUM skips it. Wrap the result in VALUE when you need a number.

In short

  • Characters are numbered from 1, and spaces and dashes count.
  • LEFT takes from the start, RIGHT from the end, and MID from any position you choose.
  • The result is text, so leading zeros stay.

Practice

4 exercises · free with an account

Start practicing
  1. Not started

    1. Country codes for the VAT report

    Formula · easy

  2. Not started

    2. Match payments by the last four digits

    Formula · medium

  3. Not started

    3. Stock by color

    Formula · medium

  4. Not started

    4. Chilled goods on the cold truck

    Formula · hard