Text function

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])
ArgumentWhat it means
textRequiredThe text or cell to search.
delimiterRequiredThe text that marks the split point. Can be an array of several delimiters.
instance_numOptionalWhich occurrence to split at. Default 1. Negative numbers count from the end.
match_modeOptional0 (default) case-sensitive; 1 ignore case.
match_endOptional1 treats the end of the text as a delimiter, so text without the delimiter is returned whole. Default 0.
if_not_foundOptionalValue 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

B2fx=TEXTBEFORE(A2," ")
AB
1Full name
2Maria LopezMaria

Result: Maria

Everything before the first space is returned.

2Everything before the last hyphen

B2fx=TEXTBEFORE(A2,"-",-1)
AB
1Product code
2PRD-2026-0458PRD-2026

Result: PRD-2026

-1 splits at the last hyphen, keeping the family and year.

3Username from an email

B2fx=TEXTBEFORE(A2,"@")
AB
1Email
2[email protected]ana.silva

Result: ana.silva

The part before the @ is the mailbox name.

4Single-word names with match_end

B2fx=TEXTBEFORE(A2," ",,,1)
AB
1Display name
2CherCher

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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#N/AThe 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.

LanguageFunction name
CzechTEXTPŘED
DutchTEKST.VOOR
FinnishTEKSTI.ENNEN
PolishTEKST.PRZED
Portuguese (Brazil)TEXTOANTES
Portuguese (Portugal)TEXTOANTES
RussianТЕКСТДО
SwedishTEXTFÖRE
TurkishÖNCEKİMETİN

Recipes that use TEXTBEFORE