To extract text between two characters or substrings in Excel, use the MID function combined with SEARCH (or FIND). The core formula is =MID(A1,SEARCH("start",A1)+LEN("start"),SEARCH("end",A1)-SEARCH("start",A1)-LEN("start")). This works by locating the position of the start marker, then the end marker, and returning everything in between. If you need a simpler approach for a single delimiter, you can also use TEXTBEFORE and TEXTAFTER (available in Excel 365 and Excel 2021). This guide covers both methods, plus how to handle multiple occurrences, errors, and edge cases.
What You'll Need
- Microsoft Excel (any version works for the MID/SEARCH method; TEXTBEFORE/TEXTAFTER require Excel 365 or Excel 2021)
- A column of text data containing consistent start and end markers (e.g., parentheses, brackets, or specific words)
- Basic familiarity with entering formulas in a cell
Step-by-Step
Method 1: Using MID and SEARCH (Works in All Excel Versions)
- Identify your start and end markers. For example, if you have "Product (ABC-123) in stock" and want to extract "ABC-123", your start marker is "(" and your end marker is ")".
- Click an empty cell where you want the extracted text to appear (e.g., B1).
- Enter the formula:
=MID(A1, SEARCH("(", A1)+1, SEARCH(")", A1) - SEARCH("(", A1) - 1). The +1 after the first SEARCH skips the opening parenthesis; the -1 at the end removes the closing parenthesis from the count. - Press Enter. You should see "ABC-123" appear in B1.
- Drag the fill handle (the small square at the bottom-right of the cell) down to copy the formula for other rows.
If your markers are longer than one character (e.g., "start" and "end"), adjust the formula: =MID(A1, SEARCH("start", A1)+LEN("start"), SEARCH("end", A1) - SEARCH("start", A1) - LEN("start")). The LEN function counts the characters in the marker so you skip past it correctly.
Method 2: Using TEXTBEFORE and TEXTAFTER (Excel 365/2021)
- Click an empty cell (e.g., B1).
- Enter the formula:
=TEXTBEFORE(TEXTAFTER(A1, "("), ")"). This first extracts everything after the "(", then takes everything before the ")". - Press Enter. The result will be "ABC-123".
- Copy down as needed.
This method is cleaner and easier to read. Note that if the start marker appears multiple times, TEXTBEFORE/TEXTAFTER will use the first occurrence by default. Use the [instance_num] argument to pick a specific one, e.g., =TEXTBEFORE(TEXTAFTER(A1, "(", 2), ")") for the second parenthesis.
Handling Multiple Occurrences or the Last Occurrence
If your text has multiple start markers and you want the text between the last occurrence of the start and the first occurrence of the end after that, use the FIND function with the start_num argument. For example, to extract text between the last "(" and the next ")": =MID(A1, FIND("(", A1, 1)+1, FIND(")", A1, FIND("(", A1, 1)) - FIND("(", A1, 1) - 1). This is more complex, but it works. For a simpler approach in Excel 365, use =TEXTBEFORE(TEXTAFTER(A1, "(", -1), ")") – the -1 tells TEXTAFTER to use the last occurrence.
Extracting Text Between the Same Character (e.g., Between Two Commas)
If your start and end markers are the same character, like extracting the second item in a comma-separated list, use =TRIM(MID(A1, FIND(",", A1)+1, FIND(",", A1, FIND(",", A1)+1) - FIND(",", A1) - 1)). The TRIM removes extra spaces. In Excel 365, you can use =TEXTBEFORE(TEXTAFTER(A1, ","), ",") which gives the same result.
Common Mistakes
- Forgetting the +1 or -1 adjustments. If you don't add 1 after the start marker, you'll include the marker itself in the result. If you don't subtract 1 at the end, you'll include the end marker.
- Using SEARCH when case matters. SEARCH is case-insensitive (it treats "a" and "A" the same). If you need case-sensitive matching, use FIND instead. For example,
=MID(A1, FIND("start", A1)+LEN("start"), ...). - Assuming the markers exist in every cell. If a cell doesn't contain the start or end marker, the formula returns a #VALUE! error. You need to handle this with IFERROR (see Troubleshooting).
- Using TEXTBEFORE/TEXTAFTER in older Excel. These functions are not available in Excel 2019 or earlier. If you share the file with someone using an older version, they'll see #NAME? errors.
- Not accounting for spaces. If your text has spaces around the markers (e.g., "Product ( ABC-123 )"), the result will include leading/trailing spaces. Use TRIM to clean it up:
=TRIM(MID(...)).
Tips
- Use LEN for multi-character markers. Always use LEN("marker") instead of counting characters manually – it's more accurate and easier to update.
- Nest formulas for complex extractions. You can combine MID with other functions like SUBSTITUTE, LEFT, RIGHT, or TRIM to handle unusual data.
- Test on a small sample first. Before applying the formula to hundreds of rows, test on a few cells to verify the markers are consistent.
- Use absolute references for marker strings. If you store the markers in separate cells (e.g., D1="(", E1=")"), you can reference them with $D$1 and $E$1 so you can change them without editing the formula.
- For Excel 365, consider the new TEXTSPLIT function. If you're extracting between delimiters in a list, TEXTSPLIT can break the entire string into an array, then you can index it with CHOOSECOLS or INDEX.
Troubleshooting
If the formula returns #VALUE!: This usually means the start or end marker is not found in the text. Wrap the formula in IFERROR to return a custom message or blank: =IFERROR(MID(A1, SEARCH("(", A1)+1, SEARCH(")", A1)-SEARCH("(", A1)-1), ""). This will show an empty cell instead of an error.
If the result includes extra characters: Double-check your +1 and -1 adjustments. For example, if you're extracting between "[" and "]", you need +1 after the first SEARCH and -1 at the end. If you're using TEXTBEFORE/TEXTAFTER, ensure you're not including spaces – add TRIM.
If the result is a #NAME? error: This means you're using TEXTBEFORE/TEXTAFTER in a version that doesn't support them. Switch to the MID/SEARCH method, or upgrade to Excel 365.
If the formula works for some rows but not others: Check if the markers are consistent. Maybe some rows have different casing, extra spaces, or missing markers. Use the FIND function for case-sensitive matching, or use TRIM on the source data first.
If you need to extract text between the first and second occurrence of the same character: Use the FIND function with start_num. For example, to get text between the first and second comma: =MID(A1, FIND(",", A1)+1, FIND(",", A1, FIND(",", A1)+1) - FIND(",", A1) - 1). This works by finding the second comma starting the search after the first comma.
If the text is in a different cell than expected: Make sure the cell reference (A1) matches your data. If your data starts in row 2, adjust the formula accordingly.
Frequently Asked Questions
How do I extract text between two specific words in Excel?
Use the same MID/SEARCH approach with the words as markers. For example, to extract text between "start" and "end", use =MID(A1, SEARCH("start", A1)+LEN("start"), SEARCH("end", A1) - SEARCH("start", A1) - LEN("start")). Replace "start" and "end" with your actual words.
Can I extract text between parentheses in Excel?
Yes. Use the formula =MID(A1, SEARCH("(", A1)+1, SEARCH(")", A1) - SEARCH("(", A1) - 1). This extracts everything between the first opening and first closing parenthesis. If there are multiple parentheses, it will take the first pair.
What is the difference between SEARCH and FIND in Excel?
SEARCH is case-insensitive and allows wildcards (like * and ?). FIND is case-sensitive and does not allow wildcards. Use FIND when you need exact case matching.
How do I extract text between two identical characters, like two commas?
Use FIND with a start position. For example, to get text between the first and second comma: =MID(A1, FIND(",", A1)+1, FIND(",", A1, FIND(",", A1)+1) - FIND(",", A1) - 1). In Excel 365, you can use =TEXTBEFORE(TEXTAFTER(A1, ","), ",").
Why does my formula return #VALUE!?
This happens when the start or end marker is not found in the cell. Use IFERROR to handle it: =IFERROR(MID(...), "") to return a blank instead of an error.
Can I extract text between multiple occurrences of the same marker?
Yes. Use FIND with a start_num to skip earlier occurrences. For example, to get text between the second and third comma, modify the formula to find the second comma and then the third. In Excel 365, use the instance_num argument in TEXTAFTER, like =TEXTBEFORE(TEXTAFTER(A1, ",", 2), ",") to get the text after the second comma and before the next comma.