Extracting Text Between Two Characters in Excel

📅 May 10, 2026 📝 Sarah Miller

Manually isolating nested text in Excel is tedious and prone to errors. When analyzing complex datasets-such as compiling standard funding sources like capital allocations-data often exports as cluttered strings. Fortunately, mastering targeted formulas grants you immediate analytical precision by automating this extraction.

As a stipulation, this approach assumes your specific boundary characters remain consistent throughout the dataset. For instance, extracting department codes from formatted strings like "Dept_HR_2024" provides instant, actionable categorization. Below, we outline the exact MID and FIND formula structure to streamline your workflow.

Extracting Text Between Two Characters in Excel

Data manipulation is one of the most common tasks performed in Microsoft Excel. Frequently, database exports, log files, or raw text strings pack multiple pieces of information into a single cell. A classic example is a product code formatted as PRD-9821-US, or an email string like John Doe <johndoe@example.com>. To analyze this data effectively, you often need to extract a specific substring nestled between two boundary characters (delimiters).

Depending on your version of Excel, there are several ways to accomplish this. Traditional versions of Excel require a combination of text functions like MID, SEARCH, and LEN. Modern Excel (Microsoft 365 and Excel 2021) introduces streamlined functions like TEXTBEFORE and TEXTAFTER. In this comprehensive guide, we will explore both classic and modern methodologies, ensuring you can tackle this challenge regardless of the Excel version you are using.


Method 1: The Classic Formula (MID + SEARCH/FIND)

For decades, the standard approach to extracting text between two characters has relied on a nested combination of the MID and SEARCH (or FIND) functions. This method is universally compatible with all Excel versions, from Excel 97 to the latest releases.

Understanding the Core Functions

  • MID(text, start_num, num_chars): Extracts a substring from a text string, starting at the position you specify and drawing out the number of characters you define.
  • SEARCH(find_text, within_text, [start_num]): Locates the starting position of a text string inside another text string. It is case-insensitive. (Use FIND if case sensitivity is required).

The Generic Formula Structure

To extract text between Character A and Character B, use this formula template:

=MID(cell, SEARCH("CharA", cell) + 1, SEARCH("CharB", cell) - SEARCH("CharA", cell) - 1)

Step-by-Step Breakdown

Let's unpack how this formula operates using a practical example. Suppose cell A2 contains the text: User [Admin_901] Active, and we want to extract the text inside the square brackets (Admin_901).

  1. Find the Start Position:
    SEARCH("[", A2) returns 6, which is the position of the opening bracket. Since we don't want to include the bracket itself in our output, we add 1: SEARCH("[", A2) + 1, resulting in 7.
  2. Calculate the Number of Characters to Extract:
    We need to determine the length of the string between the brackets. To do this, we find the position of the closing bracket and subtract the position of the opening bracket, then subtract 1:
    SEARCH("]", A2) - SEARCH("[", A2) - 1
    In our example, 16 - 6 - 1 = 9. This tells the formula to extract exactly 9 characters.
  3. Execute the MID Function:
    Plugging these numbers into MID:
    =MID(A2, 7, 9), which outputs: Admin_901.

Method 2: Extracting Between Identical Delimiters

A variation of this problem occurs when the starting and ending delimiters are the exact same character-for example, extracting the middle segment from a serial code like TX-88291-North where the delimiter is a hyphen (-).

If you use the standard formula here, it will fail because both searches look for the first occurrence of the character. To find the second occurrence, we must leverage the optional third argument of the SEARCH function: [start_num].

The Formula for Identical Delimiters

To extract text between the first and second occurrence of a hyphen in cell A2, use:

=MID(A2, SEARCH("-", A2) + 1, SEARCH("-", A2, SEARCH("-", A2) + 1) - SEARCH("-", A2) - 1)

How It Works

The expression SEARCH("-", A2, SEARCH("-", A2) + 1) instructs Excel to start looking for the second hyphen beginning at the position immediately following the first hyphen. This isolates the second occurrence, allowing the formula to correctly calculate the substring length.


Method 3: The Modern Way (TEXTBEFORE and TEXTAFTER)

If you are a Microsoft 365 or Excel Web user, you have access to a suite of highly efficient text manipulation functions. The combination of TEXTBEFORE and TEXTAFTER eliminates the need for complex mathematical offsets and tedious nesting.

The Modern Formula Structure

To extract text between two characters in Excel 365, use this clean and intuitive syntax:

=TEXTBEFORE(TEXTAFTER(A2, "CharA"), "CharB")

Why This Works Beautifully

  1. TEXTAFTER(A2, "CharA"): Discards everything before and including CharA, leaving only the remaining string. For User [Admin_901] Active, it leaves us with Admin_901] Active.
  2. TEXTBEFORE(..., "CharB"): Takes that intermediate result and extracts everything before CharB. This slices away ] Active, leaving us with the clean result: Admin_901.

This approach is significantly easier to write, read, and maintain than legacy MID formulas.


Handling Edge Cases and Troubleshooting

Real-world data is rarely perfect. Missing delimiters, multiple instances of characters, or casing discrepancies can break your formulas. Here is how to make your spreadsheets robust.

1. Preventing Error Values (#VALUE!)

If one or both delimiters are missing from a cell, the SEARCH function will throw a #VALUE! error. To prevent this from ruining your dashboard aesthetics, wrap your formula inside an IFERROR statement:

=IFERROR(MID(A2, SEARCH("[", A2) + 1, SEARCH("]", A2) - SEARCH("[", A2) - 1), "Delimiter Missing")

2. Case Sensitivity (SEARCH vs. FIND)

By default, SEARCH is case-insensitive. If your extraction relies on case-sensitive markers-for instance, extracting text between a lowercase "a" and an uppercase "A"-swap SEARCH with FIND:

=MID(A2, FIND("a", A2) + 1, FIND("A", A2) - FIND("a", A2) - 1)

Quick Comparison of Methods

Here is a summary table to help you decide which approach to use based on your environment and specific data needs:

Method Excel Compatibility Complexity Best For
MID + SEARCH All Versions (Legacy & Modern) Medium to High Universal compatibility, standard extraction of brackets/parentheses.
MID + SEARCH (Nested) All Versions (Legacy & Modern) High Extracting text bounded by identical characters (e.g., hyphens).
TEXTBEFORE + TEXTAFTER Excel 365, Excel 2021+ Very Low Clean, rapid formula building on modern Excel versions.

Conclusion

Extracting substrings between specific characters is an essential skill for cleaning up dirty datasets. For users on older versions of Excel, mastering the combination of MID and SEARCH is a powerful addition to your formula arsenal. If you have made the transition to Microsoft 365, adopting TEXTBEFORE and TEXTAFTER will save you time and greatly reduce the structural complexity of your workbooks.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.