The TEXTBEFORE function
TEXTBEFORE gives you everything before a marker. You don't need to count characters, so it works whatever the length of each piece.
It replaces the old LEFT(A2,FIND(" ",A2)-1) pattern with something much easier to read. A negative instance number counts markers from the end.
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
Arguments
- text
- The text (or cell) to cut.
- delimiter
- The marker to cut at, such as
" ",","or"@". - instance_numoptional
- Which occurrence of the marker to use. 1 is the first (the default); -1 is the last.
- match_modeoptional
- 0 for case-sensitive matching (the default), 1 to ignore case.
- match_endoptional
- 1 to treat the end of the text as a marker too. Usually left out.
- if_not_foundoptional
- What to return when the marker isn't there. Without it you get #N/A.
Try it
=TEXTBEFORE(A2,"@") in D2. Everything before the @ is returned: priya.shah.
D2
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Contact | File | Username | ||
| 2 | priya.shah@northwind.co.uk | Shah, Priya | invoice.march.2025.pdf | priya.shah | |
| 3 | tom.oakes@harbourmail.com | Oakes, Tom | budget-draft.xlsx | ||
| 4 | no email given | Rees, Bethan | notes | ||
| 5 | |||||
| 6 |
Edit the formula in D2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =TEXTBEFORE(B3,", ") | Oakes | The surname from a "Surname, First" list. |
| =TEXTBEFORE(C2,".",-1) | invoice.march.2025 | -1 uses the last dot, so only the file extension is dropped. |
| =TEXTBEFORE(A4,"@") | #N/A | No @ in the text, so TEXTBEFORE returns #N/A. |
| =TEXTBEFORE(A4,"@",,,,"(none)") | (none) | The last argument gives a friendlier result when the marker is missing. |
Tips
- Use TEXTAFTER with the same marker to get the other half.
- Several markers can go in curly brackets:
TEXTBEFORE(A2,{" ","-"})cuts at whichever comes first. - Leave out the optional arguments you don't need, but keep their commas if you need a later one, as in the (none) example.
Common mistakes
- You get #N/A on some rows.Those rows don't contain the marker. Add the if_not_found argument, or wrap the formula in IFERROR.
- A name with a middle name is cut in the wrong place.Pick the occurrence you need: 1 for the first space, -1 for the last.
TEXTBEFORE(A2," ",-1)keeps first and middle names. - A marker in different case isn't found.Matching is case-sensitive by default. Set match_mode to 1 to ignore case.
In Google Sheets
Google Sheets doesn't have TEXTBEFORE, and nor do desktop versions of Excel up to 2021. Use =LEFT(A2, FIND(" ", A2) - 1) there instead, or SPLIT in Sheets.
Practise TEXTBEFORE with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.