Extracting specific segments of text within Excel is a vital skill for managing and analyzing data effectively. By utilizing Excel's text functions, you can efficiently extract substrings from any part of a text string, whether it's isolating a city name from an address or retrieving usernames from email addresses.

Excel text functions to extract substrings

Several functions in Excel can help you extract substrings from text data. The key functions include:

  • MID function: Extracts a substring from the middle of a text string, starting at a specified position.
  • LEFT function: Extracts a substring from the beginning (left side) of a text string.
  • RIGHT function: Extracts a substring from the end (right side) of a text string.

Additionally, functions like FIND, SEARCH, and LEN are useful for determining positions and lengths within text strings.


Excel MID function

The MID function allows you to extract a substring from the middle of a text string, starting at any position you specify.

The syntax for the MID function is:

=MID(text, start_num, num_chars)

Where:

  • text: The text string or cell reference containing the characters you want to extract.
  • start_num: The position of the first character you want to extract.
  • num_chars: The number of characters to extract from the start position.

Example of the MID function:

Suppose we have a full name in cell A2, and we want to extract the middle name from this string. We can use the MID function as follows:

=MID(A2, 9, 4)

In this formula, Excel starts at the 9th character of the text in cell A2 and extracts the next 4 characters.

How to extract a substring between two characters

To extract text between two specific characters, you can combine the MID function with the FIND function. Use the following syntax:

=MID(text, FIND("char1", text) + 1, FIND("char2", text) - FIND("char1", text) - 1)

Where:

  • text: The text string or cell reference.
  • char1: The character after which the substring begins.
  • char2: The character before which the substring ends.

For instance, if we have an email address in cell A2 and we want to extract the domain name without the username and the '.com' part, we can use:

=MID(A2, FIND("@", A2) + 1, FIND(".", A2) - FIND("@", A2) - 1)

This formula finds the position of "@" and ".", calculates the length of the substring, and extracts the domain name.

First, FIND("@", A2) + 1 returns the position immediately after "@". Then, FIND(".", A2) - FIND("@", A2) - 1 calculates the number of characters between "@" and ".". The MID function then extracts this substring.

Another example:

=MID(A2, FIND(" ", A2) + 1, FIND(" The", A2) - FIND(" ", A2) - 1)

In this formula, FIND(" ", A2) + 1 locates the position after the first space, and FIND(" The", A2) - FIND(" ", A2) - 1 calculates the length between the space and the word "The".


Excel LEFT function

The LEFT function extracts a specified number of characters from the beginning of a text string.

The syntax for the LEFT function is:

=LEFT(text, [num_chars])

Where:

  • text: The text string or cell reference containing the characters you want to extract.
  • num_chars: The number of characters to extract from the left of the text string (including spaces).

Example of the LEFT function:

If we have an address in cell A1 and want to extract the door number and street name, we can use:

=LEFT(A1, 14)

This formula extracts the first 14 characters from the text in cell A1.

The function tells Excel to look at the text value in cell A1 and extract the leftmost 14 characters from that text string.

How to extract a substring before a specific character

To extract text before a specific character, you can combine the LEFT and FIND functions. Use the formula:

=LEFT(text, FIND("char", text) - 1)

Where "char" is the character before which you want to extract text.

For example, to get the username from an email address in cell A2:

=LEFT(A2, FIND("@", A2) - 1)

This formula finds the position of "@", subtracts 1, and extracts the characters to the left.

The FIND function returns the position of "@", and the LEFT function extracts all characters to the left of that position.

Alternatively, to extract text before a specific word (e.g., "The"):

=LEFT(A2, LEN(A2) - SEARCH(" The", A2))

This formula uses LEN and SEARCH to determine the number of characters to extract.

Here, SEARCH(" The", A2) finds the position of " The", and LEN(A2) - SEARCH(" The", A2) calculates the length to extract.


Excel RIGHT function

The RIGHT function extracts a specified number of characters from the end of a text string.

The syntax for the RIGHT function is:

=RIGHT(text, [num_chars])

Where:

  • text: The text string or cell reference containing the characters you want to extract.
  • num_chars: The number of characters to extract from the right of the text string.

Example of the RIGHT function:

Suppose we have a list of full names in column A, and we want to extract the last name from each. We can use:

=RIGHT(A2, 7)

This formula extracts the last 7 characters from the text in cell A2.

How to extract a substring after a specific character

To extract text after a specific character, combine the RIGHT, LEN, and FIND functions. Use the formula:

=RIGHT(text, LEN(text) - FIND("char", text))

For instance, to extract the domain name from an email address in cell A2:

=RIGHT(A2, LEN(A2) - FIND("@", A2))

This formula calculates the total length of the text, subtracts the position of "@", and extracts the characters to the right.

The LEN function finds the total length of the string, and FIND("@", A2) locates the position of "@". The RIGHT function then extracts the substring after "@".


By utilizing Excel's text functions like MID, LEFT, and RIGHT in combination with FIND, SEARCH, and LEN, you can effectively extract any substring from your data, enhancing your ability to manage and analyze text-based information.