Features of !SEMTools
↑ Navigate Excel tasks and !SEMTools add-in features ↑

MID

MID function examples
MID - simplest usage examples
Function categoryText
VolatilityNon-volatile
Similar functionsLEFT, RIGHT

What does the MID function do in Excel?

MID extracts a text fragment from the middle of a text string.
The function needs to know at which position the fragment to extract begins and how many characters to select.
If the number of characters to select exceeds what's available, only the available characters will be selected.

MID syntax

=MID(text, start_num, num_chars)
MID: a piece from the middle
D2=MID(A2,B2,C2)
ABCD
1Textstart_numnum_charsMID
2SKU-2026-RED542026=MID(A2,B2,C2)
3SKU-2026-RED103RED=MID(A3,B3,C3)
4SKU-2026-RED1050RED=MID(A4,B4,C4)
5SKU-2026-RED203=MID(A5,B5,C5)

If num_chars runs past the end, MID returns what’s left. If start_num is past the end, the result is an empty string, not an error.

MID: result and input format

Similar to LEFT and RIGHT.

MID usage examples

Example 1

This example shows how to extract a variable-length element that is located inside text.
In this case, it's the middle name within a full name.
The extracted name text is always located between the first and second space.

Example 1: text between the first and second space
B2=MID(A2,FIND(" ",A2)+1,FIND(" ",A2,FIND(" ",A2)+1)-FIND(" ",A2)-1)
AB
1Full nameMiddle name
2John Fitzgerald KennedyFitzgerald=MID(A2,FIND(" ",A2)+1,FIND(" ",A2,FIND(" ",A2)+1)-FIND(" ",A2)-1)
3Mary Ann SmithAnn=MID(A3,FIND(" ",A3)+1,FIND(" ",A3,FIND(" ",A3)+1)-FIND(" ",A3)-1)
4Anna Louise Maria BergLouise=MID(A4,FIND(" ",A4)+1,FIND(" ",A4,FIND(" ",A4)+1)-FIND(" ",A4)-1)

FIND(" ",A2)+1 is where the middle name starts; the second FIND looks for the next space after it. Their difference minus 1 is the length. In Excel 365 the same is =TEXTBEFORE(TEXTAFTER(A2," ")," ").

MID - extracting the second word
Extracting middle name from full name using the MID function

Example 2

The MID function is used to extract from a string the first word containing a specific fragment.
The SUBSTITUTE function in combination with REPT creates a large number of spaces between words to guarantee extracting only one word with extra spaces on the right and left.
The TRIM function then removes them.

Example 2: the first word that contains a fragment
B2=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),MAX(1,SEARCH($B$1,SUBSTITUTE(A2," ",REPT(" ",100)))-50),100))
AB
1Textups
2order 1452 shipped via ups-ground todayups-ground=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),MAX(1,SEARCH($B$1,SUBSTITUTE(A2," ",REPT(" ",100)))-50),100))
3ups-express, 2 boxesups-express,=TRIM(MID(SUBSTITUTE(A3," ",REPT(" ",100)),MAX(1,SEARCH($B$1,SUBSTITUTE(A3," ",REPT(" ",100)))-50),100))
4delivered by dhl#VALUE!=TRIM(MID(SUBSTITUTE(A4," ",REPT(" ",100)),MAX(1,SEARCH($B$1,SUBSTITUTE(A4," ",REPT(" ",100)))-50),100))

Every space becomes 100 spaces, so any 100-character window around the fragment holds only one word; TRIM removes the padding. MAX(1, …) keeps the start from going below 1 when the word is at the very beginning. Commas stay attached to the word (“ups-express,”). No match → #VALUE!; wrap in IFERROR if needed.

MID - extracting word by pattern
Extracting words containing a specific pattern using the MID function

See also:

Like the article? Help its author! Buy !SEMTools, it has lots of useful instruments to process text data.