3.1 C
London
Friday, December 20, 2024
HomeSoftware TutorialsExcelExcel: How to Use MID Function for Variable Length Strings

Excel: How to Use MID Function for Variable Length Strings

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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:

=MID(A2,FIND("char1",A2)+2,FIND("char2",A2,10)-FIND("char1",A2)-2)

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:

=MID(A2,FIND("//",A2)+2,FIND(".com",A2,10)-FIND("//",A2)-2)

The following screenshot shows how to use this formula in practice:

Excel MID function with variable length

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.

Additional Resources

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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories