TEXTBEFORE Function

Excel Functions › Text

Excel 365

The Excel TEXTBEFORE function returns everything in a text value that comes before a delimiter — the username before the @, the area code before the dash, the folder before the slash. It replaces the old LEFT(A2, FIND("@",A2)-1) contraption with one readable argument list, and it can count delimiters from the end of the text, which FIND never could. Its twin is TEXTAFTER, and for splitting into every piece at once, use TEXTSPLIT.


Quick answer: to get everything before the @ in an email address:
=TEXTBEFORE(A2, "@")
Add an instance number to pick which delimiter counts: =TEXTBEFORE(A2, "-", 2) stops at the second dash, and -1 counts from the end.

Syntax

=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
ArgumentDescription
textRequiredThe text to search in.
delimiterRequiredThe character(s) to look for. Can be more than one character.
instance_numOptionalWhich occurrence to stop at. Default 1. Negative counts from the end: -1 means the last occurrence.
match_modeOptional0 (default) = case-sensitive · 1 = case-insensitive.
match_endOptional1 treats the very end of the text as a delimiter, so a missing delimiter returns the whole text instead of an error. Default 0.
if_not_foundOptionalWhat to return when the delimiter isn’t found — without it you get #N/A.

Available in: Excel for Microsoft 365 and Excel for the web only. Excel 2021 and earlier show #NAME? — there the equivalent is LEFT(A2, FIND("@",A2)-1).

Grab the text before a delimiter

Emails sit in column A and you need the usernames. One short formula, no FIND arithmetic:

AC
1EmailUsername
2jane.doe@dfwexcel.comjane.doe
3m.alvarez@example.orgm.alvarez
4kim@plano.k12.tx.uskim
=TEXTBEFORE(A2, "@") // everything left of the @

The delimiter can be longer than one character — useful for splitting on words:

=TEXTBEFORE("Dallas - Fort Worth", " - ") // returns "Dallas"

And instance_num picks which occurrence matters when the delimiter repeats:

=TEXTBEFORE("2026-06-11-final", "-", 2) // returns "2026-06" — stops at the 2nd dash

Try it: interactive TEXTBEFORE demo

Live demo

Edit the text, pick a delimiter and an instance number — including negatives, which count from the end.

Negative instances and power moves

Negative instance_num is the headline feature — counting from the end used to take a SUBSTITUTE/FIND tangle. Get the folder path from a full file path by stopping at the last slash:

=TEXTBEFORE("reports/2026/q2/sales.xlsx", "/", -1) // returns "reports/2026/q2"

Strip a file extension the same way — everything before the last dot:

=TEXTBEFORE(A2, ".", -1) // "archive.backup.zip" becomes "archive.backup"

Pair it with TEXTAFTER to slice out the middle of a string — the domain between @ and the final dot:

=TEXTBEFORE(TEXTAFTER(A2, "@"), ".", -1) // "jane@dfwexcel.com" gives "dfwexcel"

And make missing delimiters harmless with if_not_found — far cleaner than wrapping in IFERROR:

=TEXTBEFORE(A2, "@", , , , "no @ found") // arguments 3-5 left at their defaults

Errors & common pitfalls

#N/A — delimiter not found. The delimiter (or the nth instance you asked for) doesn’t exist in the text. Supply if_not_found for a graceful fallback, or set match_end to 1 to have the whole text returned instead.

#VALUE! — instance_num is 0 or out of range. Zero is never valid, and an instance number larger than the text could possibly hold also fails.

#NAME? — older Excel. TEXTBEFORE exists only in Excel for Microsoft 365 and Excel for the web. Elsewhere, use =LEFT(A2, FIND("@",A2)-1).

Pitfall: matching is case-sensitive by default. Searching for "x" ignores "X" until you set match_mode to 1.

Pitfall: the delimiter is not included. TEXTBEFORE stops before the delimiter — no trailing @ or slash in the result. If you expected it, concatenate it back on.

Practice workbook

📊
Download the free TEXTBEFORE practice workbook
Every example on this page, ready to open in Excel — plus practice challenges with answers on a separate tab. No sign-up required.

Frequently asked questions

What's the difference between TEXTBEFORE and TEXTAFTER?
Mirror images: TEXTBEFORE returns the text to the left of the delimiter, TEXTAFTER the text to the right. They share an identical argument list, and together they slice any middle piece out of a string.
How do I get the text before the LAST occurrence of a character?
Use a negative instance number: =TEXTBEFORE(A2, "/", -1) stops at the last slash. That one argument replaces the old SUBSTITUTE-and-FIND workaround entirely.
How do I avoid #N/A when the delimiter might be missing?
Two clean options: pass a fallback as the sixth argument — =TEXTBEFORE(A2, "@", , , , "none") — or set match_end to 1, which treats the end of the text as a delimiter and returns the whole string.
What's the TEXTBEFORE equivalent for older Excel versions?
The classic pattern is =LEFT(A2, FIND("@", A2) - 1). It handles only the first occurrence and errors when the delimiter is missing, so wrap it in IFERROR for safety.
Can the delimiter be more than one character?
Yes — any string works: =TEXTBEFORE(A2, " - ") splits at a spaced dash, and an array of delimiters like {",",";"} matches whichever comes first.

Master functions like this in one day

This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related functions: TEXTAFTER · TEXTSPLIT · TEXTJOIN · IFERROR · CONCAT