The MID function in Excel allows you to extract a specific number of characters from a string based on a starting position on the left side of the string.
However, sometimes you want to extract middle characters based on a specific starting and ending character.
You can use the MID function combined with the FIND function to do so:
This particular formula extracts every character in the string in cell A2 between the characters char1 and char2.
The following example shows how to use this formula in practice.
Example: MID Function for Variable Length Strings in Excel
Suppose we have the following list of websites URL’s:
Suppose we would like to extract only the website name between the double forward slashes (//) and the .com near the end of the URL.
We can use the following formula to do so:
The following screenshot shows how to use this formula in practice:
Column B now displays only the characters in the website name between the double slashes // and the .com near the end of the name.
Note that this formula works even though the length of each website name is not the same.
Without using the FIND function, the MID function alone would not be able to perform this task.
The following tutorials explain how to perform other common tasks in Excel:
Excel: A Formula for MID From Right
Excel: A Formula for “If Not Empty”
Excel: How to Ignore Blank Cells When Using Formulas