Function · Split and regex
Excel TEXTBEFORE function
The Excel TEXTBEFORE function returns the text before a delimiter. Everything before the comma in Austin, TX 78701 is Austin.
Syntax =TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
=TEXTBEFORE("Austin, TX 78701",",")Arguments
| Name | Required | What to pass |
|---|---|---|
| text | Required | The text to cut. |
| delimiter | Required | The mark to stop at. The mark itself is not included in the result. |
| instance_num | Optional | Which occurrence. 1, the default, is the first. A negative number counts from the end. |
| match_mode | Optional | 0, the default, is case-sensitive. 1 ignores case. |
| match_end | Optional | 0, the default, does not treat the end of the text as a delimiter. 1 does. |
| if_not_found | Optional | What to return when the delimiter is missing. If omitted, a miss is #N/A. |
Examples
The city in Austin, TX 78701
=TEXTBEFORE(B1,",")Result Austin
| A | B | |
|---|---|---|
| 1 | Line | Austin, TX 78701 |
| 2 | City | Austin |
TEXTBEFORE returns the characters in front of a delimiter and drops the delimiter. In Austin, TX 78701 the first comma sits right after Austin, so the result is Austin. The space after the comma stays with the state. TEXTAFTER on the same comma would start at that space unless you include the space in the delimiter.
The third argument picks which match. 1 is the first comma. -1 is the last. A missing delimiter is #N/A unless you pass if_not_found. Excel 2021 does not have this function. LEFT and FIND are the older way to take the same slice.