TEXTBEFORE function
TEXTBEFORE returns everything before a delimiter you name, such as the username before the @ in an email or the first name before a space. It needs no position math, and it can count from the end to split at the last delimiter instead of the first.
- Available in
- Excel 2024 and Microsoft 365
- Category
- Text functions
- Returns
- The text before the chosen delimiter.
Syntax
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
| Argument | Required? | What it is |
|---|---|---|
text | Required | The text or cell to split. |
delimiter | Required | The character or text to split at. |
instance_num | Optional | Which delimiter to use: 1 for the first (default), 2 for the second, -1 for the last. |
match_mode | Optional | 0 for a case-sensitive match (default), 1 to ignore case. |
match_end | Optional | 1 treats the end of the text as a delimiter, so text without one comes back whole. The default is 0. |
if_not_found | Optional | What to return when the delimiter isn't there, instead of #N/A. |
Examples
Each result below is calculated from the sample sheet by our formula engine, the same one that grades the practice.
| Cell | Formula | Result | What it shows |
|---|---|---|---|
| D2 | =TEXTBEFORE(A2,"@") | maya.chen | The username before the @ |
| D3 | =TEXTBEFORE(C3," ",-1) | Raj Kumar | Everything before the last space |
| D4 | =TEXTBEFORE(C4," ",,,,C4) | Cher | No space at all, so if_not_found returns the whole name instead of #N/A |
Try it live
This is the sample sheet. Change any number or text, or edit a formula, and the results update.
Show the sample data as a table
| File | Full name | Result | |
| maya.chen@acme.com | Q3_report_final.xlsx | Maya Chen | maya.chen |
| raj@globex.io | budget_2026.csv | Raj Kumar Patel | Raj Kumar |
| lee.wong@initech.net | notes.txt | Cher | Cher |
Practice TEXTBEFORE
From lesson 16, TEXTBEFORE, TEXTAFTER & FIND. Graded instantly, then re-checked on changed data.
Username
B2, return everything before the @. Fill down to B6.Common mistakes
| What you see | Why, and how to fix it |
|---|---|
| #N/A | The delimiter isn't in the text. Set if_not_found: =TEXTBEFORE(A2," ",,,,A2) returns the whole text instead. |
| #NAME? | TEXTBEFORE is only in Excel 2024 and Microsoft 365. In older versions, use =LEFT(A2,FIND("@",A2)-1). |
| The split is missed because of case | The match is case-sensitive by default, so "X" won't split at "x". Set match_mode to 1. |
Tips
- Get the text between two delimiters by nesting: =TEXTBEFORE(TEXTAFTER(A2,"("),")").
Questions
How do I get the text before a character in Excel?
In Excel 2024 or Microsoft 365, use =TEXTBEFORE(A2,"-"). In older versions, use =LEFT(A2,FIND("-",A2)-1).
How do I extract the first name from a full name?
=TEXTBEFORE(A2," ") returns everything before the first space. Add if_not_found, =TEXTBEFORE(A2," ",,,,A2), so single-word names come back whole.
Lessons that use TEXTBEFORE
Last reviewed October 2026. Every example result on this page is calculated live by the Spreadsheet Practice formula engine.