Return to Excel Formulas List

Extract Text from Cell – Excel & Google Sheets

Download Example Workbook

Download the example workbook

This tutorial will demonstrate how to extract text from a cell in Excel and Google Sheets.

extract text from cell main

Extract Text from Left

You can extract text from the left side of a cell in Excel by using the LEFT Function. Simply supply the text, and enter the number of characters to return.

extract text left excel

However, this will only extract a fixed number of characters. You can see above some cook temperatures are correct extracted (ex. 300), but some are not (ex. 95F). To create a dynamic formula that will work in all scenarios are we can use the LEN Function, combined with the LEFT Function.

LEN Function – Count Characters in a Cell

Use the LEN Function to count the number of characters in the cell:

extract text from cell 02

 

LEFT Function – Show Characters from the Left

Then, create a new LEFT Function that extracts a number of characters determined by the LEN Function created above.

extract text from cell 03

Combining these functions looks like this:

extract text left len excel

RIGHT and LEN Functions

Similarly, we can also extract characters from the right of a cell by using the RIGHT Function to return a certain number of characters from the right.

extract text from cell 4

MID and SEARCH Functions

In the next section, we will use the SEARCH and MID functions to extract characters from the middle of a text string.

extract text from cell 07 00

SEARCH Function

First, we use the SEARCH Function to find the position of the space (” “) between the first and last names.

extract text from cell 07 01

MID Function

Next, we use the MID Function to return all the characters after the space.

 

  • We need to add 1 to the result of the previous formula so that we return the first character after the space.
  • We use the large number 999 to return all characters.

extract text from cell 07 02

Combining these 2 functions gives us the original formula for the last name.

extract text from cell 07 00

Extract Text Before or After a Specific Character

You can also use the LEFT, RIGHT, LEN and SEARCH functions to extract the text before or after a specific character. In this case we will separate first and last names.

extract text from cell 08

Extract Text Before Character

First, we can use the SEARCH Function to find the position of the comma in the text string.

extract text from cell 09

Next, we can use the LEFT function to extract the text before the position of the comma.

  • We need to subtract 1 from the position of the comma so not to include the comma in our result.

extract text from cell 09 01

Combining these 2 functions gives us the original formula for the last name.

Extract Text After Character

extract text from cell 08

In addition to using the SEARCH function once again, we also use the LEN function in conjunction with the RIGHT function to get extract text after a specific character.

The LEN Function is to get the length of the text in B3, while the SEARCH function is once again used to find the position of the comma.  We then use the RIGHT function to extract the characters after the comma in the text string.

Extract Text From Middle of Text String

Next, we will discuss how to extract text from the middle of a text string

To extract text from the middle of a text string, we can use the RIGHT, SEARCH and LEN functions to get the text from the right side of the string, and then use the MID and LEN functions to get the text in the middle. We will also incorporate the TRIM function to trim any spaces on either side of the text string.

extract text from cell 10

This formula will only work if there is more than one space in the text string. If there is only one space, an error with #VALUE would be returned.

To solve this problem, for names without middle names or initials, we can use the original formula using the MID and SEARCH Functions.

We can create a single formula that uses both techniques to handle all situations with the IFERROR Function. (The IFERROR Function performs a calculation. If that calculation results in an error, then another calculation is performed.)

extract text from cell 12

We can then use the MID and LEN functions to obtain the middle name or initial.

extract text from cell 10 MID

 

Extract Text From Cell in Google Sheets

All the examples above works the same way in Google Sheets.

extract text from cell Google