TEXTBEFORE Function

Returns the text that comes before a delimiter.

Category

Text

Available in

Microsoft 365, Excel 2024

Returns

Text

Taught hands-on in Level 4: Advanced Dynamic Arrays & Logic - Advanced Math & Text module

Overview

TEXTBEFORE returns everything before a character or word you specify — the part of an email before the @, a first name before the space.

It replaces the old LEFT + FIND combination, and can count from the end with a negative instance number.

Syntax

=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Arguments

ArgumentRequired?What it does
textYesThe text to search.
delimiterYesThe character or text to stop at.
instance_numOptionalWhich occurrence to use. 1 = first (default); -1 = last.
match_modeOptional1 ignores case. Default 0.
match_endOptional1 treats the end of the text as a delimiter. Default 0.
if_not_foundOptionalWhat to return when the delimiter isn't found. Default #N/A.

Examples

Example 1 — Username from an email

Take everything before the @.

B2fx=TEXTBEFORE(A2, "@")
AB
1EmailUsername
2ana.lopez@northstar.comana.lopez
3ben.cho@northstar.comben.cho
4cara@partner.cacara
=TEXTBEFORE(A2, "@") Explain

Example 2 — Everything before the last dash

Drop the colour code from the end of each SKU.

B2fx=TEXTBEFORE(A2, "-", -1)
AB
1SKUBase SKU
2NS-1042-BLUNS-1042
3NS-2210-REDNS-2210
4NS-0087-GRNNS-0087
=TEXTBEFORE(A2, "-", -1) Explain

Common mistakes

  • #N/A when there's no delimiter. Use the last argument: =TEXTBEFORE(A2, " ", , , , A2) returns the whole text when there's no space.

Notes

Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.