Text
The text string to look in.
Delimiter
The delimiter marking the start of the text to return.
Which
A number which specifies which occurrence of the delimiter to use, counting from the left. A negative number counts from the right, meaning that -1 denotes the last occurrence. If omitted, the first occurrence is used. Zero is not a valid value.
FallbackValue
The value to return if the delimiter cannot be found as many times as the Which parameter requires. If omitted, an #N/A error is used.
Returns
The text which precedes the delimiter.
Returns the text which precedes a delimiter in a text string. TEXTBEFORE ("first-second", "-") TEXTBEFORE ("first-second"; "-") returns "first", the text which precedes the first occurrence of the delimiter "-".
Use the third parameter to pick another occurrence of the delimiter. A negative number counts from the right, meaning that TEXTBEFORE ("Ada Maria Lovelace", " ", - 1) TEXTBEFORE ("Ada Maria Lovelace"; " "; - 1) returns "Ada Maria", everything but the last name.
Handling text strings without the delimiter
If the delimiter does not appear in the text string — or appears fewer times than the third parameter requires — an #N/A error is returned. Give the fourth parameter to return a value of your choosing instead:
This formula returns "not found" instead of an error.
Matching is case-sensitive
The delimiter must match exactly, including its case. Use the LOWER or UPPER functions to match regardless of case, by converting both the text string and the delimiter to the same case.
Use TEXTSPLIT to get every part of a text string instead of the text on one side of a delimiter. Use REGEXEXTRACT when the text to find is better described by a regular expression than by a literal delimiter. Use TEXTAFTER to get the text which follows the delimiter.
Examples
Returns "first".
Returns "a-b", as the text preceding the second occurrence of "-" is returned.
Returns "Ada Maria", everything but the last name. The Which parameter is -1, meaning that the last occurrence of " " is used.
Returns "david", the user name of the email address.
Returns "not found", as the delimiter "-" does not appear in the text string and a fallback value is given.
Returns an empty text string, as no text precedes the delimiter.