For years, pulling a username out of an email address or grabbing a filename from the end of a Windows folder path in Excel meant nesting LEFT, RIGHT, LEN, and FIND—and praying there wasn’t an extra hyphen or slash. With TEXTBEFORE in Excel and its counterpart TEXTAFTER, you can extract any substring before or after a delimiter using a single, readable formula.
Availability & Compatibility: Per the official TEXTBEFORE function documentation and TEXTAFTER function documentation, both functions are available in Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel for the web, Excel 2024, and Excel 2024 for Mac. They are not supported in Excel 2021 or earlier perpetual versions (which return #NAME?), and Google Sheets uses SPLIT or REGEXEXTRACT instead.
Table of Contents
How TEXTBEFORE in Excel Works (Syntax & Arguments)
TEXTBEFORE returns all characters occurring before a specified delimiter string. Here is the full six-argument syntax:
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
- text (Required): The cell or text string you are searching within. Wildcard characters are not supported.
- delimiter (Required): The character or substring marking where extraction stops (for example, “@”, “-“, or “”).
- instance_num (Optional): Which occurrence of the delimiter to stop at. Defaults to 1. Negative numbers count backward from the end of the text.
- match_mode (Optional): Set to 0 for case-sensitive matching (default) or 1 for case-insensitive matching.
- match_end (Optional): Set to 1 to treat the end of the text as a virtual delimiter if no delimiter is found (default 0).
- if_not_found (Optional): Custom fallback value returned instead of #N/A when the delimiter doesn’t appear.
Suppose cell B6 in our Practice sheet holds the email [email protected]. To extract only the username before the @ symbol, enter:
=TEXTBEFORE(B6, "@")
How TEXTAFTER Works (Including Negative Instance Numbers)
TEXTAFTER uses the exact same six arguments as TEXTBEFORE, returning everything after the chosen delimiter instead of before it:
=TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
To pull the domain name from [email protected], use =TEXTAFTER(B6, “@”). Where TEXTAFTER truly beats legacy RIGHT/FIND formulas is handling repeated delimiters with a negative instance_num. For example, cell B10 holds a nested Windows file path: C:ReportsQ4Sales_2026.csv. Passing -1 grabs everything after the last backslash—no matter how many subfolders exist:
=TEXTAFTER(B10, "\\", -1)
This returns Sales_2026.csv cleanly. If you need to split a string into every segment across multiple columns at once rather than extracting one piece, use TEXTSPLIT in Excel, or switch to Excel REGEX functions when your delimiter pattern varies.
TEXTBEFORE vs. TEXTAFTER vs. Legacy LEFT/RIGHT/FIND
See how the modern text-extraction functions compare against classic formulas:
| Goal | Modern Formula | Legacy Formula | Advantage | Text before @ |
|---|---|---|---|---|
| =TEXTBEFORE(B6, “@”) | =LEFT(B6, FIND(“@”, B6)-1) | No math or nested FIND | Text after @ | =TEXTAFTER(B6, “@”) |
| =RIGHT(B6, LEN(B6)-FIND(“@”, B6)) | No LEN subtraction | Text after last | =TEXTAFTER(B10, “”, -1) | =TRIM(RIGHT(SUBSTITUTE(…))) |
| One simple -1 argument | Missing delimiter | =TEXTBEFORE(B6, “@”,,,, “None”) | =IFERROR(LEFT(…), “None”) | Built-in fallback parameter |
Troubleshooting #N/A, #VALUE!, and Case-Sensitivity Issues
- #N/A error: Per Microsoft Support, Excel returns #N/A when delimiter does not exist in text or when instance_num exceeds the number of times the delimiter appears. Supply a fallback in the sixth argument (if_not_found) or set match_end to 1 when extracting single-word entries.
- #VALUE! error: Returned if instance_num is 0 or larger than the total character length of text.
- Case mismatch returns #N/A: By default, match_mode is 0 (case-sensitive). Pass 1 as the fourth argument (=TEXTBEFORE(A2, “sku”, , 1)) to match regardless of uppercase or lowercase.
- #NAME? error: The workbook was opened in Excel 2021 or older, or in Google Sheets, where TEXTBEFORE and TEXTAFTER are unavailable.
- Frequently Asked Questions
For more dynamic array workflows, see our CHOOSECOLS and CHOOSEROWS in Excel guide.
What is the difference between TEXTBEFORE and TEXTAFTER in Excel?
TEXTBEFORE returns the text occurring before a specified delimiter, while TEXTAFTER returns the text occurring after that delimiter.
How do I extract text after the last occurrence of a delimiter?
Pass -1 for the third argument (instance_num)—for example, =TEXTAFTER(B10, “”, -1)—to search backward from the end of the string.
How do I extract text between two delimiters in Excel?
Nest TEXTBEFORE inside TEXTAFTER (or vice versa): =TEXTBEFORE(TEXTAFTER(A2, “-“), “-“) to isolate the middle segment between the first and second hyphens.
Download the practice workbook
The same data as this tutorial, with empty answer cells and a Solutions sheet.