Cleanup function
Excel TEXTBEFORE function
TEXTBEFORE returns everything in a text string before a character or word you choose. Use it to pull usernames out of emails, first names out of full names, or prefixes out of product codes.
=TEXTBEFORE(text, delimiter)Arguments
text- The text to split, usually a cell.
delimiter- The character or text to stop at, in quotes.
TEXTBEFORE examples
Every result below was calculated from this sample sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | |
|---|---|---|---|
| 1 | Name | SKU | |
| 2 | maria.lopez@northwind.com | Maria Lopez | TSH-BLU-M |
| 3 | dev.patel@harborfoods.org | Dev Patel | MUG-WHT-12 |
| 4 | kim@lakeside.io | Kim Ng | CAP-BLK |
Result: maria.lopez
Returns the username: maria.lopez.
Result: Dev
Everything before the first space is the first name, Dev.
Result: MUG
Pulls the product family code, MUG, from the SKU.
Result: #N/A
There is no comma in the name, so you get #N/A.
Result: Kim Ng
Wrap it in IFERROR to fall back to the full text.
How to use TEXTBEFORE
- Click the cell for the result.
- Type =TEXTBEFORE( and click the text cell.
- Type a comma and the delimiter in quotes.
- Press Enter, then fill down.
Common TEXTBEFORE mistakes
Getting #N/A
The delimiter is not in the text. Add an if_not_found value as the sixth argument, or wrap it in IFERROR.
Using it in older Excel
TEXTBEFORE is in Microsoft 365, Excel 2024 and Excel for the web. In older versions use LEFT with FIND.
Case does not match
The match is case-sensitive by default. Set match_mode, the fourth argument, to 1 to ignore case.
TEXTBEFORE FAQ
How do I extract text before a character in Excel?
Use =TEXTBEFORE(A2,"-"). In older Excel, use =LEFT(A2,FIND("-",A2)-1).
How do I get the first name from a full name in Excel?
Use =TEXTBEFORE(A2," ") to take everything before the first space.
How do I get text before the second dash?
Add the instance number as the third argument: =TEXTBEFORE(A2,"-",2).
Practice TEXTBEFORE in these lessons
Guides that use TEXTBEFORE
- How to separate first and last name in Excel
- How to extract text before a character in Excel
- How to remove characters from a cell in Excel
- How to extract numbers from a string in Excel
- #VALUE! error in Excel: causes and fixes
Related functions
TEXTAFTERText after a delimiterLEFTCharacters from the startFINDPosition of text (case-sensitive)IFERRORFallback when a formula errors
Updated