What is the MID function?
=MID(text, start_num, num_chars)MID returns characters from the middle of a text. You give the position to start at and how many characters to take.
It is ideal for codes with a fixed layout, such as the year in "A-2026-0457".
Arguments
- text
- The text, or a cell containing it.
- start_num
- The position of the first character to return. The first character of the text is 1.
- num_chars
- How many characters to return. If it runs past the end, MID returns the rest of the text.
MID examples
Example 1. Year from a code
=MID("A-2026-0457", 3, 4)Starts at the 3rd character and takes 4. The result is 2026.
Example 2. Text between two dashes
=MID(A2, FIND("-", A2)+1, 4)Start right after the first dash, wherever it is.
Common mistakes
Counting from 0
start_num counts from 1. MID(text, 0, 2) returns #VALUE!.
Numbers come back as text
MID returns text. Wrap it in VALUE to calculate with it.
FAQ
- What if start_num is past the end of the text?
- MID returns empty text ("").