What MID does

MID returns characters from the middle of a text: you give it the position to start at and how many characters to take. =MID(A2,4,4) starts at character 4 of the product code UK-4471-B and returns 4471. With FIND working out the positions, it can also take the text between two dashes.

LEFT always starts at the beginning and RIGHT always ends at the end, while MID can take any stretch. It suits codes and references with a fixed layout, where a year or an order number always sits in the same place. Excel has no SUBSTRING function, so MID is the one to use when you want a substring.

Count positions carefully. The first character is 1, and every dash, slash and space counts as a character.

Syntax

=MID(text, start_num, num_chars)
Every argument is required.
textRequired
The text to take characters from, usually a cell such as A2.
start_numRequired
The position of the first character you want, counting from 1 at the start of the text. Separators and spaces count.
num_charsRequired
How many characters to take from there. If that runs past the end of the text, MID stops at the end.

Example: the number in the middle of a code

Each product code has the layout country, dash, four digits, dash, version. The digits start at character 4. The formula in B2 is filled down to B4.

U, K and the dash are characters 1 to 3, so the number starts at 4. In B2, =MID(A2,4,4) returns 4471.

Example: the order number from a long reference

References have the layout ORD/year/number/region. The five-digit order number starts at character 10.

ORD/ and 2026/ take up characters 1 to 9, so the number starts at 10. In B2, =MID(A2,10,5) returns 00381.

Text between two characters

When the layout changes from row to row, let FIND work out the positions. For the number between the two dashes in UK-4471-B:

  1. Start one character after the first dash: FIND("-",A2)+1 is 4.
  2. Find the second dash by searching from there: FIND("-",A2,FIND("-",A2)+1) is 8.
  3. Take the characters in between: the second dash’s position, minus the first dash’s position, minus 1. Here that’s 8 minus 3 minus 1, which is 4.

Put together, =MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1) returns 4471, and it still works for a code like USA-12345-B. In Microsoft 365 and Excel 2024, TEXTBEFORE and TEXTAFTER make it shorter: =TEXTBEFORE(TEXTAFTER(A2,"-"),"-").

Common mistakes

  • The first character is position 1. Counting from 0 starts MID one character too early.
  • Dashes, slashes and spaces are characters too. When a layout is new to you, write the text out and number each character.
  • If some references have a three-letter prefix and others four, a fixed start number cuts in the wrong place. Find the separator’s position with FIND and start one character after it.
  • MID returns text, so “00381” keeps its zeros and won’t add up. Use VALUE when you need the number.

Frequently asked questions

How do I extract text between two characters?

Use FIND to locate both characters, then take what lies between them with MID: =MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1) returns 4471 from UK-4471-B. In Microsoft 365 and Excel 2024, =TEXTBEFORE(TEXTAFTER(A2,"-"),"-") is shorter, and for a one-off cleanup Flash Fill is often quicker.

Is there a SUBSTRING function in Excel?

No, MID does that job: =MID(A2,4,4) returns 4 characters starting at position 4. LEFT and RIGHT take a substring from the start or the end of the text.

How do I take everything from a position to the end?

Give MID a num_chars at least as long as the rest of the text, for example =MID(A2,5,LEN(A2)). It stops at the end of the text.

What does MID return if start_num is past the end?

Empty text, "". There’s no error, so the cell just looks blank.

Can MID count from the right?

Not by itself, because start_num always counts from the left. Work the start out with LEN: in UK-4471-B the number starts 6 characters from the end, so =MID(A2,LEN(A2)-5,4) returns 4471, even for a longer prefix like USA-4471-B.