Excel function

MIDfunction

Returns a given number of characters from the middle of a text, starting at a position you choose.

All versions
=MID("A-2026-0457", 3, 4)

Text11 chars

1A
2-
32
40
52
66
7-
80
94
105
117

Result4 chars

12
20
32
46

Click a character and drag: where you click is start_num and the length you drag is num_chars. Try breaking it on purpose to see the errors.

Result

2026

text

The text to take characters from.

start_num

The position of the first character to take. The first character is 1.

num_chars

How many characters to take.

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

  1. Example 1. Year from a code

    =MID("A-2026-0457", 3, 4)

    Starts at the 3rd character and takes 4. The result is 2026.

  2. Example 2. Text between two dashes

    =MID(A2, FIND("-", A2)+1, 4)

    Start right after the first dash, wherever it is.

Common mistakes

FAQ

What if start_num is past the end of the text?
MID returns empty text ("").