In this lesson we will learn how the MID function works in Excel. The MID function is used to extract a specified number of characters from a string.
=MID(text, start_num, num_chars)
- text – the string from which you want to extract the sub-string.
- start_num – the starting position within the string, from where the extraction should begin.
- num_chars – the total number of characters you want to extract.
Let’s understand with a simple example. In below table, we have added the formula as follows in cell B2.
Here the MID function is extracting 3 characters from the 6th position of the string in A2.
In the below example since there are couple of extra spaces in the string in A2, we used TRIM function to remove the extra spaces and then used the below MID function in cell B2 to extract 3 characters from the 6th position of the string in A2.
- If the start number is greater than the length of the string, MID returns “” (empty text).
- If the number of characters is 0, MID returns “” (empty text).
- The number of characters cannot be negative.
- The start number cannot be less than 1.
- If the number of characters specified is larger than the total no. of characters in the string, the entire string is returned(beginning from the start number)