The MID function
MID takes a slice out of the middle of some text. You give it where to start and how many characters to take.
It suits fixed-layout codes, like booking references where the month is always in the same place. Positions count from 1, so the fifth character is position 5.
=MID(text, start_num, num_chars)
Arguments
- text
- The text (or cell) to take characters from.
- start_num
- The position of the first character you want. The first character of the text is 1.
- num_chars
- How many characters to take, starting from
start_num.
Try it
=MID(A2,5,3) in B2. Starting at the 5th character (after B, K, 2 and 5), three characters give MAR.
B2
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Booking ref | Month | ||
| 2 | BK25MAR0193 | MAR | ||
| 3 | BK25APR0207 | |||
| 4 | BK24DEC0058 | |||
| 5 | BK25JAN0311 | |||
| 6 | ||||
| 7 |
Edit the formula in B2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =MID(A2,3,2) | 25 | The two-digit year sits at positions 3 and 4. |
| =MID(A4,8,10) | 0058 | Asking for more characters than are left is fine: MID stops at the end of the text. |
| =MID(A3,4,3) | 5AP | Starting one position too early, the classic off-by-one slip, picks up the last digit of the year. |
Tips
- To find the start position, count the characters before the piece you want and add 1.
- For pieces that move around, use FIND to work out the start:
=MID(A2,FIND("-",A2)+1,4)takes four characters after the first dash. - A very large
num_charssuch as 100 is a handy way to say "everything to the end".
Common mistakes
- The slice is one character out (5AP instead of APR).
start_numis the position of the first character you want, counting from 1. Count the characters before it and add 1. - MID returns #VALUE!.
start_nummust be 1 or more. A calculated start that works out as 0 or less, such asFIND(...)-1when the character is first, is the usual cause. - A year pulled out with MID won't work in DATE or sums.MID returns text. Add zero (
MID(A2,3,2)+0) or use VALUE to turn it into a number.
Practise MID with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.