Skip to content

TEXTAFTER

Returns the text that comes after a delimiter, counting from the start or the end of the text.

Syntax

=TEXTAFTER(, , , , , )

Text

Excel for Microsoft 365, Excel 2024 and later, and Excel for the web. Not available in Excel 2021 or earlier.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
Email
Team
Domain
2
dana.whitfield@example.com
Finance
example.com
3
li@corp.example
Sales
4

C2 =TEXTAFTER(A2,"@") returns example.com

How TEXTAFTER works

TEXTAFTER returns the text that comes after a delimiter. Use it to take the domain from an email address, the lot code at the end of a batch number, or the value after a label such as Ref:. It replaces the combination of MID, FIND and LEN that older workbooks needed.

The arguments

  • text is where to look.
  • delimiter is the marker that starts the part you want.
  • instance_num says which occurrence of the delimiter to use. The default is the first. A negative number counts from the end.
  • match_mode is case-sensitive by default. Set it to 1 to ignore case.
  • match_end set to 1 treats the start of the text as a delimiter.
  • if_not_found is what to return when the delimiter isn't there. Without it you get #N/A.

=TEXTAFTER("dana.whitfield@example.com","@") returns example.com.

Choosing the occurrence

For PW-24-0113-A7:

  • =TEXTAFTER(A2,"-") returns 24-0113-A7, everything after the first dash.
  • =TEXTAFTER(A2,"-",2) returns 0113-A7, everything after the second.
  • =TEXTAFTER(A2,"-",-1) returns A7, everything after the last.

The negative instance is the feature that earlier formulas found hardest. The last word after a space, the file name after the last slash, and the extension after the last dot all become one short formula: =TEXTAFTER(A2,".",-1).

When the delimiter is missing

TEXTAFTER returns #N/A if the delimiter isn't in the text. Supply the sixth argument to replace it: =TEXTAFTER(A2,"-",1,0,0,"No lot"). IFERROR also works.

Case

Matching is case-sensitive unless match_mode is 1. =TEXTAFTER("Ordered. REF: 7719","ref: ",1,1) finds the label despite the different capitals and returns 7719.

Compared with the older formulas

The old way to get the text after a dash was =MID(A2,FIND("-",A2)+1,100) or =RIGHT(A2,LEN(A2)-FIND("-",A2)). Both work in every version of Excel, and you will still see them. TEXTAFTER is shorter and is less likely to break when text is longer than the number you guessed. If the workbook has to open in Excel 2021 or earlier, use those instead.

Between two markers

Combine it with TEXTBEFORE to cut text from the middle: =TEXTBEFORE(TEXTAFTER(A2,"("),")") returns what sits inside the first pair of brackets. The inner TEXTAFTER drops everything up to the opening bracket, and the outer TEXTBEFORE drops everything from the closing one.

Results are text

TEXTAFTER returns text. If the part after the delimiter is a number, convert it with VALUE. Any spaces next to the delimiter stay in the result, so include them in the delimiter, as in ": ", or wrap the result in TRIM. To get every piece, rather than one, use TEXTSPLIT.

Arguments

text
The text to search. Usually a cell such as A2.
delimiter
The text that marks the start of the part you want, such as "@" or "-". It can be several characters long, or an array of alternatives such as {"-","/"}.
instance_numoptional
Which occurrence of the delimiter to use. The default is 1, the first. A negative number counts from the end, so -1 is the last one. 0, or a number larger than the text length, returns #VALUE!.
match_modeoptional
0, the default, is case-sensitive. 1 ignores case.
match_endoptional
1 treats the start of the text as a delimiter. The default, 0, doesn't.
if_not_foundoptional
What to return when the delimiter isn't found, such as "No dash". By default TEXTAFTER returns #N/A.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

The domain after the @

C2 =TEXTAFTER(A2,"@")

Result: example.com

Everything after the first @.

C2
A
B
C
1
Email
Team
Domain
2
dana.whitfield@example.com
Finance
example.com
3
li@corp.example
Sales
4

C2 =TEXTAFTER(A2,"@") returns example.com

Example 2

The lot code after the last dash

C3 =TEXTAFTER(A3,"-",-1)

Result: B12

-1 counts delimiters from the end, so this finds the text after the last dash, whatever its length.

C3
A
B
C
1
Batch code
Qty
Lot
2
PW-24-0113-A7
400
3
GL-25-0207-B12
250
B12
4

C3 =TEXTAFTER(A3,"-",-1) returns B12

Example 3

Everything after the second delimiter

C2 =TEXTAFTER(A2,"-",2)

Result: 0113-A7

Instance 2 starts after the second dash. The remaining dash stays in the result.

C2
A
B
C
1
Batch code
Qty
Serial and lot
2
PW-24-0113-A7
400
0113-A7
3
4

C2 =TEXTAFTER(A2,"-",2) returns 0113-A7

Example 4

Ignore case when matching a label

C2 =TEXTAFTER(A2,"ref: ",1,1)

Result: 7719

The label is lower case in the formula and in capitals in the text. match_mode 1 ignores the difference. The space after the colon is part of the delimiter, so it is not in the result.

C2
A
B
C
1
Note
Source
Reference
2
Ordered. REF: 7719
Email
7719
3
4

C2 =TEXTAFTER(A2,"ref: ",1,1) returns 7719

Example 5

Return your own message when the delimiter is missing

C3 =TEXTAFTER(A3,"-",1,0,0,"No suffix")

Result: No suffix

FX1085 has no dash. The sixth argument replaces the #N/A that would otherwise show.

C3
A
B
C
1
Code
Owner
Suffix
2
FX-1010
Finance
3
FX1085
Planning
No suffix
4

C3 =TEXTAFTER(A3,"-",1,0,0,"No suffix") returns No suffix

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, return the part of the email address in A2 after the @. Fill it down to B5.

Answer in B2, then it fills down to B5.

B2
A
B
C
D
1
Email
Domain
File
Extension
2
dana.whitfield@example.com
report.final.xlsx
3
li@corp.example
budget.csv
4
priya.nair@example.org
notes.v2.txt
5
sam.chen@example.net
summary.pdf
6
7

Common mistakes

  • By default, a missing delimiter returns #N/A. Give if_not_found a value, or wrap the formula in IFERROR.
  • An instance_num of 0 returns #VALUE!. An instance number higher than the number of delimiters returns #N/A.
  • Matching is case-sensitive by default. If the delimiter is a label such as "ref:", set match_mode to 1.
  • The result is text. A number after the delimiter won't add up until you wrap the formula in VALUE.
  • Spaces next to the delimiter stay in the result. Include them in the delimiter, such as ": ", or wrap the formula in TRIM.
  • TEXTAFTER isn't available in Excel 2021 or earlier, where it shows #NAME?. Use MID or RIGHT with FIND there.

Questions people ask

How do I get the text after a character in Excel?

Use `=TEXTAFTER(A2,"-")`, with your character in quotes. In older versions, use `=MID(A2,FIND("-",A2)+1,100)`.

How do I get the text after the last space or slash?

Set instance_num to -1: `=TEXTAFTER(A2," ",-1)` or `=TEXTAFTER(A2,"/",-1)`. A negative number counts delimiters from the end.

How do I get the file extension from a name?

Use `=TEXTAFTER(A2,".",-1)`. The -1 makes it use the last dot, so names with several dots work too.

Why does TEXTAFTER return #N/A?

The delimiter isn't in the text, or there are fewer occurrences than instance_num asks for. Check the spelling and case, or supply if_not_found.

How do I get the text between two characters?

Combine the two functions: `=TEXTBEFORE(TEXTAFTER(A2,"("),")")` returns the text between the first opening and closing bracket.

Learn TEXTAFTER in a real sheet.

TEXTAFTER is taught in Logic and text, lesson 13: TEXTBEFORE and TEXTAFTER. Each lesson is a short, graded exercise like the one above.