Data ManagementBeginner6 min read

Extract Certain Text from a Cell in Excel

Extract text before, after, or between characters in Excel, or find known labels and flag missing matches for review.

To extract certain text from a cell in Excel, choose a formula based on where the text appears:

Text to extractMethod
Before a characterTEXTBEFORE
After a characterTEXTAFTER
Between 2 charactersTEXTAFTER inside TEXTBEFORE
A known label in varying positionsSEARCH

For example, enter this text in Text Extractor!A2:

Ticket 104 | Sales | High

Before the first pipe:

=LET(result,IFERROR(TRIM(TEXTBEFORE(A2,"|")),""),IF(result="","No match",result))

Expected result: Ticket 104

After the first pipe:

=LET(result,IFERROR(TRIM(TEXTAFTER(A2,"|")),""),IF(result="","No match",result))

Expected result: Sales | High

Between the first 2 pipes:

=LET(result,IFERROR(TRIM(TEXTBEFORE(TEXTAFTER(A2,"|"),"|")),""),IF(result="","No match",result))

Expected result: Sales

These formulas work when source cells use consistent delimiters. If known labels can appear in different positions, use the approach in Step 3 instead.

What You'll Need

Step-by-Step Guide

1

Verify the before, after, and between formulas

Keep the sample text in Text Extractor!A2, then place the three opening formulas in these cells:

  • E2: formula for text before the first pipe
  • F2: formula for text after the first pipe
  • G2: formula for text between the first 2 pipes

Verify these results in Excel:

CellExtractionExpected result
E2Before the first pipeTicket 104
F2After the first pipeSales | High
G2Between the first 2 pipesSales

Now check an empty middle field by replacing A2 with:

Ticket 104 | | High

G2 should return No match because trimming removes the spaces between the delimiters.

Then replace A2 with:

General note

All three formulas should return No match because the required pipe delimiter is absent.

If your data uses another delimiter, such as "/" or "-", replace "|" in the formulas. Restore the original A2 value before continuing.

    2

    Extract by position in older Excel versions

    If your Excel version doesn’t support TEXTBEFORE or TEXTAFTER, you can use LEFT, RIGHT, MID, and FIND.

    With Ticket 104 | Sales | High restored in A2, extract everything before the first pipe:

    =IFERROR(TRIM(LEFT(A2,FIND("|",A2)-1)),"No match")
    

    Expected result: Ticket 104

    To extract everything after the first pipe, use:

    =IFERROR(TRIM(RIGHT(A2,LEN(A2)-FIND("|",A2))),"No match")
    

    Expected result: Sales | High

    For the text between the first 2 pipes, use:

    =IFERROR(TRIM(MID(A2,FIND("|",A2)+1,FIND("|",A2,FIND("|",A2)+1)-FIND("|",A2)-1)),"No match")
    

    Expected result: Sales

    Verify each result in your version of Excel. These formulas return No match when a required pipe is absent. Unlike the opening formulas, however, a segment containing only spaces may return a blank after TRIM.

      3

      Extract known labels and flag missing matches

      When departments or priorities can appear in different positions or use inconsistent separators, switch to a known-label formula.

      Set up Text Extractor!A1:D7:

      CellValue
      A1Source text
      B1Extracted department
      C1Extracted priority
      D1Status
      A2Ticket 104 | Sales | High
      A3Support request - Low
      A4Finance review / Medium
      A5Sales follow-up / Medium
      A6Warehouse note / High
      A7General note

      Text extraction table with source descriptions, extracted departments and priorities, and review statuses.

      Enter descriptive text in column A; columns B and C extract recognized labels, while column D flags incomplete matches.

      In Text Extractor!B2, enter this department formula:

      =IF(NOT(ISTEXT(A2)),"No match",IF(IFERROR(ISNUMBER(SEARCH("Sales",A2)),FALSE),"Sales",IF(IFERROR(ISNUMBER(SEARCH("Support",A2)),FALSE),"Support",IF(IFERROR(ISNUMBER(SEARCH("Finance",A2)),FALSE),"Finance","No match"))))
      

      The formula checks Sales, Support, and Finance in that order. If several labels appear, this precedence determines the result regardless of their order in the source text.

      Next, enter this priority formula in Text Extractor!C2:

      =IF(NOT(ISTEXT(A2)),"No match",IF(IFERROR(ISNUMBER(SEARCH("High",A2)),FALSE),"High",IF(IFERROR(ISNUMBER(SEARCH("Medium",A2)),FALSE),"Medium",IF(IFERROR(ISNUMBER(SEARCH("Low",A2)),FALSE),"Low","No match"))))
      

      Here, Excel checks High, Medium, and Low in that order.

      Finally, enter the review-status formula in Text Extractor!D2:

      =IF(OR(B2="No match",C2="No match"),"Review","Ready")
      

      Select B2:D2 and fill the formulas down through row 7. Your results should be:

      RowDepartmentPriorityStatus
      2SalesHighReady
      3SupportLowReady
      4FinanceMediumReady
      5SalesMediumReady
      6No matchHighReview
      7No matchNo matchReview

      Review means that at least one recognized label is missing. Ready means only that both formulas found matching character sequences. It doesn’t indicate approval or independent validation.

      Test the following cases individually. Temporarily replace A2, confirm the results in B2:D2, and restore the original value after each test:

      • Finance escalation - Low should return Finance, Low, and Ready.
      • Numeric 0 should return No match, No match, and Review.
      • A blank cell should return No match, No match, and Review.
      • sales request - low should return Sales, Low, and Ready.
      • Support handoff to Sales - Medium should return Sales, Medium, and Ready because Sales has precedence.

      Understand the SEARCH substring limitation

      Excel’s SEARCH function is case-insensitive, and it finds character sequences rather than complete words or fields:

      • highlight contains High.
      • follow-up contains low.

      As a result, SEARCH can create unintended matches. For example, Sales follow-up / Medium returns Medium because the formula checks Medium before Low. If a description contained follow-up without High or Medium, the formula could incorrectly return Low.

      Use delimiter extraction when a label must occupy a complete field. If capitalization must match, FIND is case-sensitive, although it still matches partial words.

      To expand the table, copy B7:D7 downward and enter new descriptions in column A. Review any flagged rows, descriptions containing multiple recognized labels, and possible partial-word matches.

      For related cleanup techniques, see Google Sheets Data Cleaning for Finance.

      ModelMonkey can inspect spreadsheet context and help adjust formulas in Google Sheets or Excel. For this example, you could ask:

      Inspect Text Extractor!A2:D7 and help me add Operations after Finance in the department precedence. Preserve the No match and Review behavior.

      Before filling a proposed formula down, check it against the source descriptions, especially where substring matches could affect the result.

        Wrapping Up

        Use TEXTBEFORE and TEXTAFTER when the required text appears before, after, or between consistent delimiters. In Excel versions without those newer functions, use LEFT, MID, and RIGHT.

        When known labels can appear anywhere in a cell, SEARCH can return a department or priority, while IFERROR provides a No match fallback. Before relying on the extracted values, check for possible substring matches.

        Frequently Asked Questions

        Why does Excel show #NAME? for TEXTBEFORE, TEXTAFTER, or LET?

        Your Excel version may not support the function, or it may expect localized function names. Use the LEFT, MID, and RIGHT alternatives in Step 2. Also check whether your regional settings require semicolons instead of commas.

        Is SEARCH case-sensitive?

        No. SEARCH("Sales",A2) can match Sales, SALES, or sales. Use FIND when capitalization must match, remembering that FIND still matches partial words.

        Why can SEARCH return the wrong label?

        SEARCH matches character sequences rather than complete words. It can find High inside highlight or Low inside follow-up. Use consistently delimited fields when labels must be exact.

        What happens when several known labels appear in one cell?

        The formula returns the first match according to its declared precedence. Departments are checked as Sales, Support, then Finance. Priorities are checked as High, Medium, then Low.

        How do I return a blank instead of No match?

        Replace "No match" with "" in the relevant formula. Keeping No match makes missing labels visible and easier to filter for review.