Excel TEXTAFTER function: extract text after specific character or word

When working with complex datasets in Excel, you may often find yourself in a situation when you need to extract data to the right of a certain character or word. This tutorial will show you the fastest way by using the span-new TEXTAFTER function.

TEXTAFTER function in Excel

The Excel TEXTAFTER function returns text that appears after a given character or substring, which is called the delimiter. In case there are multiple occurrences of the delimiter, you can choose the target occurrence. If the delimiter is not found, the function can return the #N/A error, your own text, or the original string.

The syntax of TEXTAFTER is as follows:

TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

The function has 6 arguments, of which only the first two are required.

text (required) - the text to extract from. Can be supplied in the form of a string or cell reference.

delimiter (required) - a character or substring after which to do the extraction.

instance_num (optional) - the instance of the delimiter after which to extract text. The default value is 1. A negative number starts searching from the end of the original text.

match_mode (optional) - defines the delimiter's case-sensitivity. Enabled by default.

  • 0 (default) - case-sensitive
  • 1 - case-insensitive

match_end (optional) - treats the end of text as delimiter. Disabled by default.

  • 0 (default) - match the delimiter exactly as specified in the formula.
  • 1 - consider the end of text as delimiter. Here's how it practically works: if both match_end and instance_num are 1, Excel returns an empty string if delimiter is not found. If match_end is 1 and instance_num is -1, the entire string is returned if delimiter is not found.

if_not_found (optional) - the value to return if the delimiter is not present in the source text. If not set, a #N/A error is returned.

TEXTAFTER availability

Currently, the TEXTAFTER function is only available in the Office Insider Beta channel of Excel 365.

Tips:

Basic Excel text after formula

First things first, let's get to know how to build an Excel TEXTAFTER formula in its simplest form using only the required arguments (the first two).

Excel formula: extract text after character

To extract the text that appears after a specific character, you supply the reference to the cell containing the source text for the first (text) argument and the character in double quotes for the second (delimiter) argument.

For example, to extract text after space the formula is:

=TEXTAFTER(A2, " ") Excel formula to extract text after space

Excel formula: get text after string

To return the text that occurs after a certain substring, use that substring for the delimiter.

For example, if the last and first names are separated by a comma and a space, use the string ", " for delimiter:

=TEXTAFTER(A2, ", ") Excel formula to extract text after a substring

Excel formula: extract text after word

In Excel terms, a "word" is nothing else but a "substring". So, to copy text after a specific word into another cell, specify the word as the delimiter.

For instance, to get the text after the word "color", use this formula:

=TEXTAFTER(A2, "color ")

Please note that the delimiter includes a space after the word "color " to avoid leading spaces in the results. Excel formula to get text after a specific word

Now that you've got a grasp of the basics, let's investigate a few more complex scenarios.

Return text after Nth occurrence of delimiter

To get text that appears after the nth instance of the delimiter, make use of the instance_num parameter.

For example, to extract the text after the second comma, you use the string ", " for delimiter and the number 2 for instance_num:

=TEXTAFTER(A2, ", ", 2)

Again, the delimiter includes a space because, in the original text, the values are separated by a comma and a space. Return text after the nth instance of the delimiter.

Get text after last occurrence of delimiter

To extract the text after the last occurrence of the delimiter, use a negative value for the instance_num argument.

For example, to return the text after the last comma in A2, set instance_num to -1:

=TEXTAFTER(A2, ", ", -1) Get text after the last occurrence of the delimiter.

To extract the text after the last but one comma, set instance_num to -2:

=TEXTAFTER(A2, ", ", -2) Extract text after the last but one comma.

Get text after multiple delimiters

To handle multiple delimiters at a time, you can use an array constant like {"x","y","z"} in your TEXTAFTER formula, where x, y, and z are different characters or substrings.

For instance, in the dataset below, the delimiter is either a comma or semicolon, with or without a space. To handle all four variations of the delimiter correctly, we use the array constant {",",", ",";","; "}:

=TEXTAFTER(A2, {",",", ",";","; "}) Get text after multiple delimiters

If delimiter not found, return your own text

If the TEXTAFTER function cannot match delimiter in the original text string, it returns a #N/A error by default. In many situations it makes more sense to output a custom value instead. For this, you need to define the if_not_found argument (the last one).

For example, if the word "color " does not exist in cell A2, this formula would throw a #N/A error:

=TEXTAFTER(A2, "color ") If the delimiter is not found, a #N/A error is returned.

To return a blank cell instead, we supply an empty string ("") for if_not_found:

=TEXTAFTER(A2, "color ", , , , "")

Alternatively, you can type any text or character you want, say a hyphen "-":

=TEXTAFTER(A2, "color ", , , , "-") If the delimiter is not found, return any text or character you want.

If delimiter is not found, return original text

To return the original text every time the TEXTAFTER function cannot match the delimiter, this is what you need to do:

  • Set instance_num to -1 to search the source string from right to left.
  • Set match_end to 1 to treat the end of the string as the delimiter.

When searching backwards, the beginning of the string becomes the "end", so the formula returns the entire text when the delimiter is not found.

In our case, the delimiter is a substring consisting of a colon and a space:

=TEXTAFTER(A2, ": ", -1, ,1)

If the delimiter is not present in a given cell, the entire cell contents are returned. If the delimiter is not found, TEXTAFTER returns the original text.

TEXTAFTER formula case-sensitive and case-insensitive

By default, the Excel TEXTAFTER function is case-sensitive, treating lowercase and uppercase delimiters as different ones. To make the formula case-insensitive, set the match_mode argument to 1 or TRUE.

For example, the below formula only accepts the lowercase "color " as the delimiter:

=TEXTAFTER(A2, "color ") Case-sensitive TEXTAFTER formula

To make the formula case-insensitive, so it accepts the word-delimiter regardless of the letter case, we set the match_mode argument to 1:

=TEXTAFTER(A2, "color ", ,1) Case-insensitive TEXTAFTER formula

Excel TEXTAFTER function not working

If the function does not exist in your Excel, please check out TEXTAFTER availability.

If the function results in an error, it's most likely to be one of these reasons:

A #N/A error occurs when:

  • The delimiter is not found the source string. To fix the error, configure the if_not_found argument as explained in this example.
  • The instance_num value is higher than the total number of the delimiters in text.

A #VALUE! error occurs when:

  • The instance_num argument is set to 0.
  • The instance_num value is higher than the total length of text.

That's how to use the TEXTAFTER function to extract text after a specific character or word in Excel 365. I thank you for reading and hope to see you on our blog next week!

Practice workbook for download

TEXTAFTER function – formula examples (.xlsx file)

You may also be interested in: