MID Function in Excel

Part 1: Introduction

💡 Definition: The MID function in Microsoft Excel extracts a specified number of characters from a text string, starting at a specific position. It allows you to retrieve a portion of text based on the desired length and starting point.

🎯 Purpose: The MID function extracts a substring from a longer text string. It enables you to isolate and extract specific characters or words within a text string based on their position.

📜 Syntax & Arguments:

syntax
MID(text, start_num, num_chars)

🔍 Explain the Arguments:

  • text: The text string from which you want to extract the substring.
  • start_num: The position within the text string where the extraction should begin.
  • num_chars: The number of characters you want to remove from the text string.

📤 Return value: The MID function returns the specified number of characters from the text string, starting at the specified position.

💬 Remarks:

  • The start_num argument must be a positive number or a reference to a cell containing a positive number.
  • The num_chars argument must also be a positive number or a reference to a cell containing a positive number.
  • If the start_num is greater than the length of the text string, the MID function will return an empty string.
  • If the num_chars If more significant than the number of characters remaining in the text string after the specified position, the MID function will return all the characters from the fixed position to the end of the text string.

Now let’s explore some examples to understand how to use the MID function effectively.

Part 2: Examples

✨ Example 1: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, 7, 5)

Explanation: In this example, we have text strings in column A, and we want to extract a specific substring starting from the 7th position and containing 5 characters. By using the MID function with the start_num the argument set to 7 and the num_chars the argument set to 5, we can retrieve the substring “World”. The result in cell B2 will be “World”.

✨ Example 2: 

AB
1Sentence
2The quick brown fox
3Excel functions are powerful
4Data analysis is interesting

📝 Formula: In cell B2, enter =MID(A2, 5, 5)

Explanation: In this example, we have sentences in column A, and we want to extract a specific substring starting from the 5th position and containing 5 characters. Using the MID function with the start_num argument set to 5 and the num_chars view set to 5, we can retrieve the substring “quick”. The result in cell B2 will be “quick”.

 

✨ Example 3: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, 1, 5)

Explanation: In this example, we have text strings in column A, and we want to extract the first 5 characters from each line. By using the MID function with the start_num the argument set to 1 and the num_chars the view set to 5, we can retrieve the substring “Hello” from “Hello World”. The result in cell B2 will be “Hello”.

✨ Example 4:

AB
1Sentence
2The quick brown fox
3Excel functions are powerful
4Data analysis is interesting

📝 Formula: In cell B2, enter =MID(A2, 15, 9)

Explanation: In this example, we have sentences in column A, and we want to extract a specific substring starting from the 15th position and containing 9 characters. By using the MID function with the start_num the argument set to 15 and the num_chars the view set to 9, we can retrieve the substring “are powerful”. The result in cell B2 will be “are powerful”.

✨ Example 5: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, 7, LEN(A2)-6)

Explanation: In this example, we have text strings in column A, and we want to extract the substring from the 7th position until the end of each line. By using the MID function with the start_num argument set to 7 and the num_chars the view set to the length of the text string minus 6 (to account for the first 6 characters), we can retrieve the substring “World” from “Hello World”. The result in cell B2 will be “World”.

 

✨ Example 6: 

AB
1Sentence
2The quick brown fox
3Excel functions are powerful
4Data analysis is interesting

📝 Formula: In cell B2, enter =MID(A2, 1, LEN(A2))

Explanation: In this example, we have sentences in column A and want to extract the entire sentence. By using the MID function with the start_num the argument set to 1 and the num_chars the view set to the length of the text string, we can retrieve the entire sentence. The result in cell B2 will be the same as cell A2, which is “The quick brown fox”.

✨ Example 7: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, LEN(A2)-4, 5)

Explanation: In this example, we have text strings in column A, and we want to extract a specific substring starting from the fifth character before the end of the line and containing five characters. By using the MID function with the start_num the argument set to the length of the text string minus four and the num_chars we can retrieve the substring “World” from “Hello World” in the view set to five. The result in cell B2 will be “World”.

✨ Example 8: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, LEN(A2), 1)

Explanation: In this example, we have text strings in column A, and we want to extract the last character from each line. By using the MID function with the start_num the argument set to the length of the text string and the num_chars the view is set to one; we can retrieve the last character. The result in cell B2 will be “d” from “Hello World”.

✨ Example 9: 

AB
1Text
2Hello World
3Excel is fun
4Coding is cool

📝 Formula: In cell B2, enter =MID(A2, 7, LEN(A2)-12)

Explanation: In this example, we have text strings in column A, and we want to extract a substring starting from the seventh character and excluding the last five characters. By using the MID function with the start_num argument set to 7 and the num_chars the view set to the text string length minus 12, we can retrieve the substring “World” from “Hello World”. The result in cell B2 will be “World”.

Part 3: Tips and Tricks

1️⃣ Use the MID function to extract a specific number of characters from a text string based on their position.
2️⃣ Experiment with different combinations of start_num and num_chars to extract the desired substring from the text string.
3️⃣ If you want to extract a variable number of characters based on a specific condition, consider combining the MID function with other functions like IF or LEN to create dynamic formulas.
4️⃣ Keep in mind that the position specified by the start_num argument counts each character, including spaces, within the text string.
5️⃣ Ensure that the start_num and num_chars arguments are appropriate for your requirement, as incorrect values may result in unexpected outputs.
6️⃣ Remember that the MID function is case-sensitive to consider uppercase and lowercase characters differently.
7️⃣ Be cautious when using the MID function with non-text data types. Convert numbers, dates, or other data types to text before applying the MID function.
8️⃣ If you need to extract characters from a text string’s left or right side, consider using the LEFT or RIGHT functions, respectively.
9️⃣ Practice using the MID function with different examples to enhance your familiarity and proficiency in manipulating text strings.

By applying these tips and exploring various scenarios, you can use the MID function in Microsoft Excel to extract desired substrings from text strings.