(Office Insider Beta only)
Windows: 2203 (Build 15104)
Mac: 16.60 (220304)

Returns text that occurs before a given character or string. It is the opposite of the TEXTAFTER function.

Syntax

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

The TEXTBEFORE function syntax has the following arguments:

text       The text you are searching within. Wildcard characters are not allowed. If text is an empty string, Excel returns empty text. Required.

delimiter       The text that marks the point before which you want to extract. Required.

instance_num       The nth instance of delimiter that you want to extract.  By default, instance_num = 1.  A negative number starts searching text from the end. Optional.

match_mode    Searches the text for a delimiter match. By default, a case-sensitive match is done. Optional.

match_end     Treats the end of text as a wildcard match. By default, the text is an exact match. Optional. Enter the following:

  • 0      Don't match the delimiter against the end of the text.

  • 1      Match the delimiter against the end of the text.

if_not_found    Value returned if no match is found. By default, #N/A is returned. Optional.

ignore_case       Specify TRUE to make the search case-insensitive. The default is FALSE which means the search is case-sensitive. Optional.

Remarks

When searching with an empty delimiter value, TEXTBEFORE matches immediately. It returns empty text when searching from the front (if instance_num is positive) and the entire text when searching from the end (if instance_num is negative).

Example

Result

=TEXTBEFORE("Red riding hood’s, red hood", "hood")

Red riding

=TEXTBEFORE("Red riding hood’s, red hood", "")

=TEXTBEFORE("Red riding hood’s, red hood", "", -1)

Red riding hood’s, red hood

Errors

  • Excel returns a #VALUE! error if instance_num = 0.

  • Excel returns a #N/A error if delimiter isn’t contained in text.

  • Excel returns a #N/A error if instance_num is greater than the number of occurrences of delimiter in text.

Examples

Copy the example data in each of the following tables and paste it in cell A1 of a new Excel worksheet. If you need to, you can adjust the column widths to see all the data.

Data

Red

Little Red Riding Hood's red hood

basket

red

Little Red Riding Hood's red hood

Formulas

Results

=TEXTBEFORE(B2,A2)

Little 

=TEXTBEFORE(B3,A2)

#N/A

=TEXTBEFORE(B4,A4,2)

#N/A

=TEXTBEFORE(B4,A4,-2)

#N/A

=TEXTBEFORE(B4,A2,,FALSE)

Little

=TEXTBEFORE(B4,A4,3)

#N/A

See Also

Text functions (reference)

TEXTSPLIT function

TEXTAFTER function

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Office Insiders

Was this information helpful?

What affected your experience?

Thank you for your feedback!

×