How to Use MID Function for Variable Length in Excel

The MID function in Excel is used to extract a specific number of characters from a text string, starting from a specified position. It can be helpful when you need to extract some portion of the text with variable length.

Here's the syntax for the MID function:

MID(text, start_num, num_chars)

Where:

Example: Using MID function for Variable Length in Excel

Let's say you have a list of email addresses, and you want to extract the usernames (the part before the '@' symbol) which have variable lengths. Here's how to do it using the MID function:

  1. Open Excel and enter the email addresses in column A, starting from cell A1.
A
1  john.doe@example.com
2  jane_d@example.com
3  mary-smith@example.com
  1. In cell B1, enter the following formula to extract the username:
=MID(A1, 1, SEARCH("@", A1) - 1)

This formula uses the SEARCH function to find the position of the '@' symbol and then extracts the characters from the beginning of the text up to the '@' symbol using the MID function.

  1. Press Enter to see the extracted username in cell B1.
  2. Now, click on the bottom-right corner of cell B1 and drag it down to apply the formula to the other cells in column B. You should see the usernames extracted for all the email addresses in the list.
A                       B
1  john.doe@example.com     john.doe
2  jane_d@example.com       jane_d
3  mary-smith@example.com   mary-smith

That's it! You have successfully used the MID function to extract variable-length text in Excel.

Did you find this useful?