Note: in this example, we are calculating the end position in order to extract a substring with a literal start and end position. However, if you know the number of characters to extract, you can just plug in that number directly.
In the example on this page, we are using the MID function to extract text based on a start and end position. The MID function accepts three arguments: a text string, a starting position, and the number of characters to extract. The text comes from column B, and the starting position comes from column C. The number of characters to extract is calculated by subtracting the start from end, and adding 1. In cell E6:
=MID(B5,C5,D5-C5+1)=MID("Perfect is the enemy of good",1,7-1+1)=MID(B5,1,7)// returns "Perfect"
Functions to extract substrings
Excel provides three primary functions for extracting substrings:
=MID(txt,start,chars)// extract from middle=LEFT(txt,chars)// extract from left=RIGHT(txt,chars)// extract from right
Click on function names above for details and linked examples.
Finding start and end positions with a formula
In the example shown, start and end positions are based on hardcoded values. However, it is possible to calculate positions with the FIND function and SEARCH function. See links below for examples.
The foundation of this formula is the MID function, which extracts a specific number of characters from text, starting at a specific location. To figure out where to start extracting text, we use this expression: SEARCH ( "(" , B5 ) + 1...
Starting from the inside out, the MID function is used to extract all text after "@": MID ( B5 , FIND ( "@" , B5 ), LEN ( B5 )) The FIND function provides the starting point, and for total characters to extract, we just use LEN on the...
In this example, the goal is to split a text string at the underscore("_") character with a formula. Notice the location of the underscore is different in each row. This means the formula needs to locate the position of the underscore character...
In this example, the goal is to remove non-numeric characters from a text string with a formula. Working from the inside out, the MID function is used to extract the text in B5, one character at a time. The key to this step is the use of the ROW...
The Excel MID function extracts a given number of characters from the middle of a supplied text string. For example, =MID("apple",2,3) returns "ppl".
Excel Formula Training
Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.