ExcelReady
CourseFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before the interview. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Function guides
  • Blog

Product

  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. TEXTBEFORE and TEXTAFTER in Excel

TEXTBEFORE and TEXTAFTER in Excel

By ExcelReady Team·Updated October 30, 2026·7 min read

The short answer

TEXTBEFORE returns the text before a delimiter, and TEXTAFTER returns the text after it. =TEXTBEFORE(A2,"@") gives the username of an email, and =TEXTAFTER(A2,"@") gives the domain. A third argument picks which occurrence: -1 means the last one. They need Microsoft 365, Excel for the web or Excel 2024; in older Excel, use LEFT or MID with FIND.

Key takeaways

  • Syntax: =TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]). TEXTAFTER has the same parts.
  • instance_num chooses which delimiter: 2 is the second, -1 is the last.
  • If the delimiter isn't found, the result is #N/A. Use the if_not_found argument or IFERROR.
  • A delimiter can be several characters, like ", " (a comma and a space).
  • In Excel 2021 and older, use =LEFT(A2,FIND("@",A2)-1) instead of TEXTBEFORE.
On this page+
  1. What do TEXTBEFORE and TEXTAFTER do?
  2. How to use TEXTBEFORE and TEXTAFTER on an email address
  3. How to use a delimiter with more than one character
  4. How to split at the second or last delimiter
  5. What happens when the delimiter isn't found?
  6. How to do the same in older Excel
  7. Common mistakes with TEXTBEFORE and TEXTAFTER
  8. Related functions
  9. Practise it

TEXTBEFORE in Excel returns the text before a delimiter, and TEXTAFTER returns the text after it, with no counting and no FIND. A delimiter is the character that separates parts of the text, like the @ in an email or the / in a file path. This guide is for anyone splitting emails, names or codes, and it covers the optional arguments plus what to use if your Excel doesn't have these functions.

What do TEXTBEFORE and TEXTAFTER do?#

TEXTBEFORE returns everything before a delimiter, and TEXTAFTER returns everything after it. They share the same arguments:

Excel formula
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
=TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
ArgumentWhat it meansDefault
textThe cell to split(required)
delimiterWhere to split, in quotes(required)
instance_numWhich occurrence: 1, 2, ... or -1 for the last1
match_mode0 = match capitals exactly, 1 = ignore capitals0
match_end1 = treat the end of the text as a delimiter0
if_not_foundWhat to show if the delimiter isn't there#N/A

Most of the time you only need the first two. Version note: TEXTBEFORE and TEXTAFTER are available in Microsoft 365, Excel for the web and Excel 2024. Excel 2021 and older show #NAME?.

How to use TEXTBEFORE and TEXTAFTER on an email address#

Give the function the cell and the delimiter. With these emails in column A:

ABC
1EmailUsernameDomain
2sara.lindqvist@copperfield.iosara.lindqvistcopperfield.io
3dev.patel@copperfield.iodev.patelcopperfield.io
4m.okonkwo@ridgeway-partners.comm.okonkworidgeway-partners.com

In B2, get the username:

Excel formula
=TEXTBEFORE(A2,"@")

In C2, get the domain:

Excel formula
=TEXTAFTER(A2,"@")

The results are sara.lindqvist and copperfield.io. Fill both down (Windows: Ctrl+D; Mac: ⌘D). The delimiter itself isn't included in either result.

How to use a delimiter with more than one character#

A delimiter can be a whole piece of text, not just one character. Names stored as "Lindqvist, Sara" have a comma and a space between the parts. If you split at the comma only, every first name starts with a space. Split at both:

Excel formula
=TEXTAFTER(E2,", ")

This returns Sara. To flip the name to "First Last", join the two halves with &:

Excel formula
=TEXTAFTER(E2,", ")&" "&TEXTBEFORE(E2,",")

The result is Sara Lindqvist. For more ways to split and rebuild names, see how to split first and last names in Excel.

How to split at the second or last delimiter#

Use instance_num to choose which delimiter to split at. A positive number counts from the start, and a negative number counts from the end. Take these file paths:

A
1File Path
2Finance/2025/Q3/budget_review.xlsx
3HR/Policies/remote_work.docx
4Sales/2025/Accounts/West/pipeline.csv
GoalFormula (row 2)Result
Top folder=TEXTBEFORE(A2,"/")Finance
First two folders=TEXTBEFORE(A2,"/",2)Finance/2025
File name=TEXTAFTER(A2,"/",-1)budget_review.xlsx
Folder path=TEXTBEFORE(A2,"/",-1)Finance/2025/Q3
File extension=TEXTAFTER(A2,".",-1)xlsx

The -1 is what makes these work for paths of any depth. Row 4 has four slashes, but =TEXTAFTER(A4,"/",-1) still returns pipeline.csv.

Nesting TEXTBEFORE inside TEXTAFTER#

To get the folder that holds each file, combine the two. First cut off the file name with TEXTBEFORE, then keep only the last folder with TEXTAFTER:

Excel formula
=TEXTAFTER(TEXTBEFORE(A2,"/",-1),"/",-1)

TEXTBEFORE turns the path into Finance/2025/Q3, and TEXTAFTER returns Q3. For row 4 the result is West. The same idea pulls a company out of an email: =PROPER(TEXTBEFORE(TEXTAFTER(A2,"@"),".")) gives Copperfield.

What happens when the delimiter isn't found?#

If the delimiter isn't in the cell, TEXTBEFORE and TEXTAFTER return #N/A. That's useful as a warning, but in a report you may want something friendlier. Use the sixth argument:

Excel formula
=TEXTBEFORE(A2,"@",1,0,0,"No @")

Or wrap the formula in IFERROR: =IFERROR(TEXTBEFORE(A2,"@"),"No @"). Both show No @ for a cell without an @.

The other two optional arguments help in special cases:

  • match_mode 1 ignores capitals. =TEXTAFTER(A2,"id: ",1,1) finds "ID: ", "Id: " and "id: ".
  • match_end 1 treats the end of the text as a delimiter. =TEXTBEFORE("Sara"," ",1,0,1) returns Sara instead of #N/A, which helps when some names have no space.

You can also give a list of delimiters in curly brackets: =TEXTBEFORE(A2,{"-","_"}) splits at whichever comes first.

How to do the same in older Excel#

In Excel 2021 and older, use LEFT, MID or RIGHT with FIND. FIND returns the position of the delimiter, and the other functions take the text around it:

TEXTBEFORE / TEXTAFTEROlder Excel equivalent
=TEXTBEFORE(A2,"@")=LEFT(A2,FIND("@",A2)-1)
=TEXTAFTER(A2,"@")=MID(A2,FIND("@",A2)+1,LEN(A2))
=TEXTAFTER(A2,"@")=RIGHT(A2,LEN(A2)-FIND("@",A2))

The -1 after FIND stops LEFT just before the @, and the +1 starts MID just after it. Splitting at the last delimiter is much harder in older Excel, which is one of the best reasons to use TEXTAFTER where you can. Learn the building blocks in LEFT, RIGHT and MID explained and the LEFT function guide.

If a file must work for colleagues on older versions, use the LEFT and FIND form. Otherwise, TEXTBEFORE is shorter and easier to read.

Common mistakes with TEXTBEFORE and TEXTAFTER#

Most errors come from the delimiter or the version of Excel:

  1. #NAME?: your Excel doesn't have these functions. Use the LEFT and FIND versions above.
  2. #N/A: the delimiter isn't in the cell. Check for typos, and remember the default match is case-sensitive, so "ID:" doesn't match "id:". Use match_mode 1 to ignore capitals.
  3. A stray space in the result: you split at "," when the text has ", ". Include the space in the delimiter, or wrap the result in TRIM.
  4. The wrong part: without -1, the split happens at the first delimiter. For the last part of a path or name, use -1.
  5. Numbers that won't add up: the result is always text, so "2025" from a code isn't a number. Wrap it in VALUE.

Related functions#

TEXTSPLIT, also in Microsoft 365, splits text at every delimiter and spills the parts into neighbouring cells: =TEXTSPLIT(A2,"/") puts each folder in its own column. Once text is split, you may need to format numbers or dates inside new labels; the TEXT function guide shows how.

Practise it#

Practise TEXTBEFORE and TEXTAFTER in a live spreadsheet. You'll split emails into username and domain, rebuild "Last, First" names, and pull file names and folders out of paths with -1, plus the LEFT and FIND version for older Excel.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Get the domain of each email: everything after the @. Click C2 and use TEXTAFTER on A2 with "@" as the delimiter.

fx
ABCD
1
Email
Username
Domain
2
sara.lindqvist@copperfield.io
3
dev.patel@copperfield.io
4
m.okonkwo@ridgeway-partners.com
5
helen.zhao@copperfield.io
6
b.alvarez@ridgeway-partners.com
7
8
9

Tip: The text comes first, then the delimiter in double quotes.

Practise this in a lesson

LessonTEXTBEFORE and TEXTAFTERSplit emails, "Last, First" names and file paths at a delimiter with TEXTBEFORE and TEXTAFTER, including picking which occurrence to split at.Function guideLEFTPull the first characters from a cell with Excel's LEFT: prefixes, initials and first names. Examples, pitfalls and live practice.

Frequently asked questions

What does TEXTBEFORE do in Excel?

+

TEXTBEFORE returns everything in a cell before a delimiter you choose. =TEXTBEFORE(A2,"@") returns the part of an email address before the @.

Which Excel versions have TEXTBEFORE and TEXTAFTER?

+

Microsoft 365, Excel for the web and Excel 2024. Excel 2021, 2019 and older don't have them and show #NAME?.

How do I get the text after the last delimiter?

+

Use -1 as the instance number: =TEXTAFTER(A2,"/",-1) returns the file name after the last slash in a path.

Why does TEXTBEFORE return #N/A?

+

The delimiter isn't in the cell, or the instance you asked for doesn't exist. Check the delimiter, or set the sixth argument to show something else, as in =TEXTBEFORE(A2,"@",1,0,0,"No @").

What can I use instead of TEXTBEFORE in older Excel?

+

Use LEFT with FIND: =LEFT(A2,FIND("@",A2)-1) returns the same text as =TEXTBEFORE(A2,"@"). For TEXTAFTER, use =MID(A2,FIND("@",A2)+1,LEN(A2)).

Sources

  • TEXTBEFORE function - Microsoft Support
  • TEXTAFTER function - Microsoft Support

Written and checked by the ExcelReady Team. First published October 30, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What do TEXTBEFORE and TEXTAFTER do?
  2. How to use TEXTBEFORE and TEXTAFTER on an email address
  3. How to use a delimiter with more than one character
  4. How to split at the second or last delimiter
  5. What happens when the delimiter isn't found?
  6. How to do the same in older Excel
  7. Common mistakes with TEXTBEFORE and TEXTAFTER
  8. Related functions
  9. Practise it

Keep reading

Text· 6 min read

The TEXT Function: Format Numbers and Dates Inside Text

The TEXT function turns a number or date into text with the format you choose: =TEXT(value, format_text). For example, =TEXT(B2,"mmm d, yyyy") shows a date as Feb 3, 2025, and =TEXT(C2,"$#,##0.00") shows $1,250.50. Use it when you join numbers or dates to words, because & otherwise shows the raw stored number.

Text· 7 min read

How to Split First and Last Names in Excel

To split a full name in Excel, use =TEXTBEFORE(A2," ") for the first name and =TEXTAFTER(A2," ",-1) for the last name, which also handles middle names. In Excel 2021 and older, use =LEFT(A2,FIND(" ",A2)-1) for the first name. For a one-off job, Data > Text to Columns or Flash Fill splits names without formulas.

Text· 6 min read

LEFT, RIGHT and MID in Excel: Pull Out Part of a Cell

LEFT, RIGHT and MID pull part of the text out of a cell. LEFT(text, num_chars) takes characters from the start, RIGHT(text, num_chars) takes them from the end, and MID(text, start_num, num_chars) takes them from any position. For TX-ELC-40512, LEFT(A2,2) gives TX, MID(A2,4,3) gives ELC and RIGHT(A2,5) gives 40512.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback. The first lessons are free, with no download.

Start learning for free