Main content

Excel Extract Text Between Delimiters

By Szabó Gergő · Updated

Use TEXTBEFORE and TEXTAFTER on Microsoft 365, or MID and FIND on older Excel, to take the middle token of a code.

Syntax and arguments

=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")
text
The cell that contains delimiters, such as A2.
delimiter
The mark to split on, often - or /.

Text between delimiters examples

01
Middle token

A2 is EAST-Q3-2026.

=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")

TEXTAFTER drops EAST-, TEXTBEFORE keeps Q3.

02
Older Excel MID FIND

Same code in A2.

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

The nested FIND locates the second hyphen so MID can take Q3.

03
After the last slash

A path in A2.

=TEXTAFTER(A2,"/",-1)

Instance -1 reads from the right and returns the file name.

Common mistakes

  • Assuming every row has two hyphens

    Wrap in IFERROR when the delimiter can be missing.

  • Using LEFT when you need the middle

    LEFT only reads from the start. Use TEXTAFTER or MID.

  • Forgetting extra spaces

    TRIM the result if the source has spaces around the delimiter.

Text between delimiters FAQ

Does TEXTSPLIT exist?

Yes in Microsoft 365. =INDEX(TEXTSPLIT(A2,"-"),2) also returns the middle token.

Can I split to columns?

Data > Text to Columns is fine for a one-time split. Use formulas when the source keeps changing.

What about Google Sheets?

REGEXEXTRACT or SPLIT is usually simpler than nested FIND.