Disclosure: This post may contain affiliate links, meaning when you click the links and make a purchase, we receive a commission.

How to Use MID Function in Excel (5 Ideal Examples)

While working in Excel, we often need to extract a specific number of characters from a cell. This can be achieved by both the LEFT and the RIGHT functions. But using the LEFT and the RIGHT functions fixes the starting point of the extraction process. By using the MID function, we can counter this problem. Basically, the MID function allows us to extract a specified number of characters from a cell with a customizable starting point. In this article, we will learn 5 practical examples to use the MID function in Excel. So, let’s start the article and explore these examples.

Excel MID Function (Quick View)

The overview of the MID function is demonstrated in the following image. To be clear, we will discover more about the applications of the MID function in the following sections.

Excel MID Function


Download Practice Workbook


Introduction to Excel MID Function

The Syntax and Arguments along with the Return Value of the MID function are described in the following section.

Introduction to Excel MID Function

Summary:

  • Returns a specific number of characters from the middle of a string, given a specific starting position.
  • Works for both arrays and non-arrays.
  • Available from Excel 2003.

Syntax:

The syntax of the MID functions is:

=MID(text,start_num,num_chars)

Argument:

Argument Required/Optional Explanation
text Required The string from which characters will be extracted. It can be any text value, number, or array.
start_num Required The starting position from which characters will be extracted. It can be a single number or an array of numbers.
num_chars Required The total number of characters that will be extracted. Can be a single number or an array of numbers.

Note:

  • The first argument text can be any text value, number, or array of text values or numbers. But whether it is a text value or a number, the return value will always be a text value.
  • The next two arguments start_num and num_chars can be any number or an array of numbers.
  • If you use an array argument, the formula will be an Array Formula and you have to press Ctrl + Shift + Enter.

Return Value:

Returns a text value consisting of a specific number of characters starting from a specific position of a string.

Special Notes:

  • If the start_num argument is greater than the total number of characters of a string, the MID function will return an empty string.

For example, the formula MID(“Apple”,7,3) will return an empty string because here the start_num 7 is greater than the total length of the text “Apple”, 5.

  • If the total number of characters of the string starting from the start_num position is less than the argument num_chars, the MID function will return all the left characters starting from the start_num position.

For example, in the formula MID(“Apple”,3,7), the total number of characters starting from the start_num position 3 is 3 (“ple”), which is less than the num_chars  argument 7. So it will return only these 3 characters, “ple”.


5 Examples of Using the MID Function in Excel

In this section of the article, we will discuss five appropriate examples of using the MID function in Excel. Not to mention, we used the Microsoft Excel 365 version for this article; however, you can use any version according to your preference.


1. Using MID Function to Extract First Name

In the first example, we will learn to use the MID function to extract the First Name from a list of names. Let’s say, we have the list of names as shown in the following image. Our goal is to extract the First Name by using the MID function. Let’s follow the steps mentioned below to do this.

Using MID Function to Extract First Name in Excel

Steps:

  • Firstly, use the following formula in cell C5.
=MID(B5,1,FIND(" ",B5))

Here, cell B5 represents the first cell of the Name column.

  • After that, press ENTER.

As a result, the MID function will return the First Name as shown in the following image.

  • Finally, drag the Fill Handle to get the remaining outputs.

Final output of method 1 to Use MID Function to Extract First Name in Excel


2. Utilizing MID function to Extract the Middle Name

At this point, we will use the MID function to extract the Middle Name from the list of names. Let’s use the instructions outlined below to do this.

Steps:

  • Firstly, apply the formula given below in cell C5.
=MID(B5,FIND(" ",B5)+1,FIND(" ",B5,FIND(" ",B5)+1)-FIND(" ",B5)-1)

Formula Breakdown 

  • Here, the FIND function returns the location of a specific value (in this case position of space) from a string.
    • Here, ” “ → It is the find_text argument.
    • B5 → This indicates the within_text argument.
    • Output 6.
  • Now, MID(B5,FIND(” “,B5)+1,FIND(” “,B5,FIND(” “,B5)+1)-FIND(” “,B5)-1) → It becomes MID(B5,6+1,FIND(” “,B5,6+1)-6-1).
  • After that, FIND(” “,B5,6+1) returns 12 as output.
  • Then, MID(B5,6+1,FIND(” “,B5,6+1)-6-1) → It becomes MID(B5,6+1,12-6-1).
  • Finally, MID(B5,6+1,12-6-1) returns the Middle Name.
    • Output James.

  • Following that hit ENTER.

Utilizing MID function to Extract the Middle Name in Excel

  • Consequently, you will have the Middle Name of the first cell from the list of names as demonstrated in the following picture.

  • Finally, use the AutoFill option of Excel to get the rest of the outputs.

Final output of method 2 to Utilize MID function to Extract the Middle Name in Excel


3. Using MID Function to Extract the Last Name

Now we will extract the Last Name from some text values using the MID function of Excel.

Look at the data set below.

Using MID Function to Extract the Last Name in Excel

In the above dataset, we have the Employee IDs, Employee Names, and Email IDs of some employees of a company named Mars Group.

Let’s try to extract the Last Names of all the employees.

  • The formula will be:
=MID(C5,SEARCH(" ",C5)+1,LEN(C5)-SEARCH(" ",C5))

Here, cell C5 indicates the first cell of the Employee Name column.

Formula Breakdown

  • SEARCH(” “,C5)tells where there is a space (“ ”) in the name within cell C5. See the SEARCH function for details.
    • Output 8.
  • Here, we set the start_num argument of the MID function to SEARCH(” “,C5)+1, because we want to extract the last name which starts from just after the space, not from the space.
  • We set the num_chars argument of the MID function to LEN(C5)-SEARCH(” “,C5).
  • Here, LEN(C5) tells the total length of the name, and SEARCH(” “,C5) tells where there is a space within the name. See the LEN function for details.
  • So, LEN(C5)-SEARCH(” “,C5) tells how many characters remain after the space, this is the length of the last name.
    • Output 14-8.
  • So, MID(C5,SEARCH(” “,C5)+1,LEN(C5)-SEARCH(” “,C5)) → It becomes  MID(C5,8+1,14-8)
  • Finally, the MID function extracts all the characters of the name within the cell C5, after the space. That is the last name we are searching for.
    • Output Austin.

  • After that, drag the Fill Handle through the rest of the cells.

You see, we have got the last names of all the employees beautifully.

Now that you understand this, can you tell me the formula to extract out for all the employees whether they use gmail.com or yahoo.com for the Emails?

  • Simple! Just replace the space (“ ”) of the previous formula with a “@”.
=MID(D5,SEARCH("@",D5)+1,LEN(D5)-SEARCH("@",D5))

Note: These types of problems can also be solved using the RIGHT function of Excel.


4. Applying MID Function to Extract Last n Digits from Some Numbers

This time we will perform a comparatively easier task. We will extract the last two digits from the Employee IDs of all the employees.

  • The formula will be:
=MID(B5,LEN(B5)-2+1,2)

Formula Breakdown

  • LEN(B5)-2+1 tells us from where we have to start if we want to extract the last two digits.
    • Output 2.
  • MID(B5,LEN(B5)-2+1,2) → It becomes MID(B5,2,2)
  • Finally, the MID function extracts two digits starting from the position LEN(B5)-2+1. 
    • Output 01.

  • Enter this formula in the first cell and then double-click on the Fill Handle.

Applying MID Function to Extract Last n Digits from Some Numbers in Excel

Have a look! We have extracted the last two digits of all the Employee IDs.


Similar Readings


5. Using MID Function with Arrays

Up to now, we have used one string at a time and then dragged the Fill Handle for the rest of the strings.

But you can use all the strings within the MID function simultaneously.

Let’s try to extract the Last Names of all the employees simultaneously.

Instead of using one name at a time, we will use an array of all the names together.

  • The formula will be:
=MID(C5:C20,SEARCH(" ",C5:C20)+1,LEN(C5:C20)-SEARCH(" ",C5:C20))

Here, the range of cells C5:C20 refers to the cells of the Employee Name column.

Formula Breakdown

  • The Array Formula MID(C5:C20,SEARCH(” “,C5:C20)+1,LEN(C5:C20)-SEARCH(” “,C5:C20)) consists of 16 single formulas.
    • MID(C5,SEARCH(” “,C5)+1,LEN(C5)-SEARCH(” “,C5))
    • MID(C6,SEARCH(” “,C6)+1,LEN(C6)-SEARCH(” “,C6))
    • MID(C7,SEARCH(” “,C7)+1,LEN(C7)-SEARCH(” “,C7))
    • MID(C20,SEARCH(” “,C20)+1,LEN(C20)-SEARCH(” “,C20))
  • Each of them extracts the Last Name (See Example 3 for a detailed Formula Breakdown)

Note: This is an Array Formula. So do not forget to press Ctrl + Shift + Enter to enter this.

See, we have got the Last Names of all the employees simultaneously.


Common Errors with MID Function

In this section of the article, we will discuss some of the common errors regarding the MID function and their possible reason for occurrences.

Error When They Show
#VALUE! This shows when an argument is of the wrong data type. For example, when the start_num or the num_chars argument is a text value or a negative number.


Practice Section

In the Excel Workbook, we have provided a Practice Section on the right side of the worksheet. Please practice it yourself.

practice section to use MID function in Excel


Conclusion

That’s all for today. We have tried showing you how you can use the MID function in Excel. Hope you will find this helpful. Feel free to comment if anything seems difficult to understand. Let us know any of your MID function-related scenarios where you have stuck, we are ready to help. You can also have a look at our other useful articles on Excel functions and formulas on our website, ExcelDemy.


Related Articles

Rifat Hassan

Rifat Hassan

Hello! Welcome to my profile. Here I will be posting articles related to Microsoft Excel. I am a passionate Electrical Engineer holding a Bachelor’s degree in Electrical and Electronic Engineering from the Bangladesh University of Engineering and Technology. Besides academic studies, I always love to keep pace with the revolution in technology that the world is rushing towards day by day. I am diligent, career-oriented, and ready to cherish knowledge throughout my life.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo