# TEXTBEFORE function in Excel

> TEXTBEFORE returns everything before a delimiter you name, such as the username before the @ in an email or the first name before a space.

Source: https://spreadsheetpractice.com/functions/textbefore · Updated October 28, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

## Quick answer

- **What it does:** TEXTBEFORE returns everything before a delimiter you name, such as the username before the @ in an email or the first name before a space.
- **Syntax:** `=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])`
- **Most common use:** `=TEXTBEFORE(A2,"@")` returns maya.chen (The username before the @)
- **Available in:** Excel 2024 and Microsoft 365
- **Category:** [Text functions](https://spreadsheetpractice.com/functions/category/text)
- **Returns:** The text before the chosen delimiter.

## What it does

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.

## 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 was calculated by running the formula on the sample sheet.

| 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 |

### The sample sheet

Every formula above runs on this data:

|  | A | B | C | D |
|---|---|---|---|---|
| 1 | Email | File | Full name | Result |
| 2 | maya.chen@acme.com | Q3_report_final.xlsx | Maya Chen | maya.chen |
| 3 | raj@globex.io | budget_2026.csv | Raj Kumar Patel | Raj Kumar |
| 4 | lee.wong@initech.net | notes.txt | Cher | Cher |

## 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,"("),")").

## Related functions

- [TEXTAFTER](https://spreadsheetpractice.com/functions/textafter): TEXTAFTER returns everything after a delimiter, such as the domain after the @ or the last part of a file path.
- [LEFT](https://spreadsheetpractice.com/functions/left): LEFT returns a set number of characters from the start of a text string.
- [FIND](https://spreadsheetpractice.com/functions/find): FIND returns the position of one piece of text inside another, counting from 1.

## 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.

## Practice

A graded TEXTBEFORE exercise ("Username") is on [the TEXTBEFORE page](https://spreadsheetpractice.com/functions/textbefore). It is checked instantly, then re-checked on changed data.

Lessons that use TEXTBEFORE:

- [Lesson 21: TEXTBEFORE, TEXTAFTER & FIND](https://spreadsheetpractice.com/learn/textbefore-textafter-find) (Pro)

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
