ID EN
#Dynamic array

TEXTBEFORE

Excel Functions

Extract text before a delimiter

Syntax

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

Arguments

Parameter Description
text The text string to extract from.
delimiter The character(s) that delimit the text.
instance_num [optional] The instance of the delimiter in text. Default is 1.
match_mode [optional] Case-sensitivity. 0 = enabled, 1 = disabled. Default is 0.
match_end [optional] Treat end of text as delimiter. 0 = disabled, 1 = enabled. Default is 0.
if_not_found [optional] Value to return when no match is found. #N/A is default.

Return Value

Extracted text string

Details

The TEXTBEFORE function extracts text that occurs before a given delimiter. When multiple delimiters appear in the text, TEXTBEFORE can return text before the nth occurrence of a delimiter. TEXTBEFORE can also extract text that occurs before a given delimiter when counting from the end of a text string (i.e., get the text before the second to the last delimiter). Note that Excel has three related functions that split text: To extract the text that occurs before a specific character or substring, provide the text and the character(s) to use for delimiter in double quotes (""). For example, to extract the last name from "Jones, Bob", provide a comma in double quotes (",") as delimiter: Note that you can use more than one character for delimiter. For example to extract the first dimension in

Examples

Basic usage

To extract the text that occurs before a specific character or substring, provide the text and the character(s) to use for delimiter in double quotes

EXCEL
=TEXTBEFORE("Jones,Bob",",") // returns "Jones"
Basic usage

Note that you can use more than one character for delimiter. For example to extract the first dimension in the text string "12 ft x 20 ft", use " x "f

EXCEL
=TEXTBEFORE("12 ft x 20 ft"," x ") // returns "12 ft"
Text before with a positive instance number

The formulas below extract text before the first and second occurrence of a hyphen character ("-"):

EXCEL
=TEXTBEFORE("ABX-112-Red-Y","-",1) // returns "ABX"
=TEXTBEFORE("ABX-112-Red-Y","-",2 // returns "ABX-112"
Text before with a negative instance number

The formulas below extract the text that occurs before the last hyphen and the second to the last hyphen:

EXCEL
=TEXTBEFORE("ABX-112-Red-Y","-",-1) // returns "ABX-112-Red"
=TEXTBEFORE("ABX-112-Red-Y","-",-2) // returns "ABX-112"
Match end of text

Normally, TEXTBEFORE does not treat the end of a text string as a delimiter. For example, by default, the formula below will return #N/A because there

EXCEL
=TEXTBEFORE("ABX-123-Red-XYZ","-",4) // returns #N/A
Match end of text

If we enable match_end by providing 1, the formula behaves as if a delimiter exists after "XYZ":

EXCEL
=TEXTBEFORE("ABX-123-Red-XYZ","-",4,,1) // returns "ABX-123-Red-XYZ"

See Also

TEXTJOIN TEXTSPLIT TEXTAFTER CONCAT