TEXTBEFORE function
Returns the text that comes before a delimiter, with options for the nth or last occurrence, case-insensitive matching and a fallback.
Available in Microsoft 365, Excel 2024, Excel for the web
Excel 2024 and laterNot in Google Sheets
Syntax
TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])| Argument | What it means | |
|---|---|---|
text | Required | The text or cell to search. |
delimiter | Required | The text that marks the split point. Can be an array of several delimiters. |
instance_num | Optional | Which occurrence to split at. Default 1. Negative numbers count from the end. |
match_mode | Optional | 0 (default) case-sensitive; 1 ignore case. |
match_end | Optional | 1 treats the end of the text as a delimiter, so text without the delimiter is returned whole. Default 0. |
if_not_found | Optional | Value to return when the delimiter is missing. Default #N/A. |
Returns: The text before the chosen delimiter.
How TEXTBEFORE works
TEXTBEFORE returns everything to the left of a delimiter: the first name before a space, the username before @, the product family before the last hyphen. It replaces the old LEFT(A2,FIND(" ",A2)-1) construction with something that reads almost like English.
The optional arguments make it flexible. instance_num picks the occurrence (2 = before the second space) and negative numbers count from the right, so -1 gives everything before the last delimiter. match_mode 1 ignores case. When a value has no delimiter at all, you can either supply if_not_found or set match_end to 1, which treats the end of the text as a delimiter so a single-word name is returned whole instead of #N/A.
See TEXTAFTER for the right-hand side and TEXTSPLIT to break text into many pieces at once.
Examples
1First name
| A | B | |
|---|---|---|
| 1 | Full name | |
| 2 | Maria Lopez | Maria |
Result: Maria
Everything before the first space is returned.
2Everything before the last hyphen
| A | B | |
|---|---|---|
| 1 | Product code | |
| 2 | PRD-2026-0458 | PRD-2026 |
Result: PRD-2026
-1 splits at the last hyphen, keeping the family and year.
3Username from an email
| A | B | |
|---|---|---|
| 1 | ||
| 2 | [email protected] | ana.silva |
Result: ana.silva
The part before the @ is the mailbox name.
4Single-word names with match_end
| A | B | |
|---|---|---|
| 1 | Display name | |
| 2 | Cher | Cher |
Result: Cher
There is no space, but match_end 1 treats the end of the text as a delimiter, so the whole name is returned instead of #N/A.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#N/A | The delimiter does not occur (enough times) in the text. | Use if_not_found, match_end 1 or IFNA. |
#VALUE! | instance_num is 0 or out of range. | Use a valid positive or negative instance. |
#NAME? | Not available in Excel 2021 or older. | Use LEFT(A2,FIND(" ",A2)-1) instead. |
Tips
- Get the text between two markers by nesting:
=TEXTBEFORE(TEXTAFTER(A2,"["),"]")returns what is inside square brackets. - Pass several delimiters as an array:
=TEXTBEFORE(A2,{"-","/"})stops at whichever comes first. - Feed it a range to process a whole column at once; results spill.
Questions
How do I get everything before the second comma?
Use =TEXTBEFORE(A2,",",2).
What is the old-style alternative?
=LEFT(A2,FIND("@",A2)-1) works in every Excel version and returns the same as =TEXTBEFORE(A2,"@").
Google Sheets
Use REGEXEXTRACT(text, "^(.*?)-") or LEFT(text, FIND("-", text) - 1).
TEXTBEFORE in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Czech | TEXTPŘED |
| Dutch | TEKST.VOOR |
| Finnish | TEKSTI.ENNEN |
| Polish | TEKST.PRZED |
| Portuguese (Brazil) | TEXTOANTES |
| Portuguese (Portugal) | TEXTOANTES |
| Russian | ТЕКСТДО |
| Swedish | TEXTFÖRE |
| Turkish | ÖNCEKİMETİN |