Excel Extract Text From the End of a String in 365

How-to basics · Updated November 18, 2026

To extract everything after the last delimiter in Excel for Microsoft 365, use =TEXTAFTER(A2,"-",-1) when the text is in A2 and the delimiter is a hyphen. For example, it returns blue from order-east-blue. The negative instance number tells Excel to start searching from the end.

What “text from the end” can mean

There are a few different tasks people describe as extracting text from the end of a string. You might want the last part after a separator, such as a file extension after a period; the final word after a space; or a fixed number of characters, such as the last four digits of an identifier. The best formula depends on which of those you mean.

A delimiter is a character or sequence that separates parts of text. Common examples include a hyphen, slash, underscore, period, comma, or space. If a value contains several delimiters and you need the part after the final one, use TEXTAFTER with an instance number of -1. If you simply need a set number of characters from the right, RIGHT is more direct.

These formulas return text, even when the extracted characters look like a number. That is often useful for IDs and codes, where leading zeroes matter. If you need to calculate with the result as a number, you may need to convert it separately.

Use TEXTAFTER to get the final segment

TEXTAFTER is the clearest option in Microsoft 365 and Excel 2024. Its basic syntax is TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]). The square brackets indicate optional arguments; do not type the brackets into a formula. A positive instance number counts delimiter occurrences from the beginning, while a negative number counts from the end.

With source text in A2, the formula =TEXTAFTER(A2,"-",-1) extracts the segment after the last hyphen. For INV-2026-084, the result is 084. For north-west, it is west. If the string has only one hyphen, that hyphen is also the last one, so the formula returns the text after it.

To extract a file extension, use a period as the delimiter. With filenames in A2, =TEXTAFTER(A2,".",-1) returns xlsx for report.final.xlsx. Searching from the end matters because filenames can contain periods in the main name as well as before the extension.

To get the final word in a phrase, use a space as the delimiter. With the phrase in A2, =TEXTAFTER(A2," ",-1) returns complete from Monthly report complete. This assumes ordinary spaces separate the words; tabs, nonbreaking spaces, and other whitespace characters may need cleaning first.

Enter the formula and fill it down

Put the source strings in one column and the formula in the adjacent column. For example, if the first value is in A2, enter the formula in B2. Press Enter, then use the fill handle—the small square at the bottom-right corner of the selected cell—to copy the formula down the column. Excel adjusts A2 to A3, A4, and so on.

For example, with order codes in A2:A4 and a hyphen as the separator, enter =TEXTAFTER(A2,"-",-1) in B2 and fill down. If A2 is item-west-12, B2 returns 12; if A3 is item-east-7, B3 returns 7. The formula refers to each row’s corresponding source cell, so you do not need to rewrite it for every record.

If you want to keep the extracted results but remove the formulas, copy the result cells and use Paste Special to paste values. That is useful before sharing a file with a system that expects plain text, or before deleting the original source column. Keep a copy of the source data until you have checked that the extracted values are correct.

Extract a fixed number of characters

If “from the end” means a fixed number of characters rather than a segment after a delimiter, use RIGHT. For example, with codes in A2, =RIGHT(A2,4) returns the final four characters. From AB-7391, it returns 7391. RIGHT counts characters from the end and does not look for a separator.

A fixed character count is appropriate when the data format guarantees that the desired portion always has the same length. It is not a good substitute for finding a delimiter if the segment length varies. For example, RIGHT with four characters would return east from region-east, but it would return only west from region-west and could produce incomplete or misleading results for longer final segments.

To extract a final segment whose length varies, but only when the delimiter is always the same, TEXTAFTER is more dependable. For a last name after a comma, a final folder name after a backslash, or a product code after an underscore, identify the actual separator and search for its last occurrence.

Handle missing delimiters and extra spaces

If a cell might not contain the delimiter, TEXTAFTER normally returns an error because there is no matching occurrence. You can choose what to show when the delimiter is missing by supplying TEXTAFTER’s optional if_not_found argument. With values in A2 and a hyphen delimiter, =TEXTAFTER(A2,"-",-1,0,0,A2) returns the original value when no hyphen is found. The zeroes specify the default match mode and match-end behavior, making the final argument the fallback value.

Alternatively, wrap the extraction in IFERROR if you want a blank result for any error. With the source text in A2, =IFERROR(TEXTAFTER(A2,"-",-1),"") returns an empty string if the extraction fails. This can make a report look cleaner, but it also hides errors other than a missing delimiter. Choose a fallback that makes the problem visible if you need to audit incomplete data.

Sometimes the extracted segment has unwanted spaces around it. With the text in A2, =TRIM(TEXTAFTER(A2,"-",-1)) removes leading and trailing ordinary spaces and reduces repeated internal ordinary spaces to one. That behavior is helpful for messy imported text, but it can change intentional spacing within a result. TRIM does not remove every special whitespace character, so copied data from websites or other systems may require additional cleanup.

A delimiter at the very end of a string produces an empty result after that delimiter. For example, the final segment of code- is empty. An empty source cell may also produce an empty-looking result. These are not necessarily formula errors, so check the original data if blanks are unexpected.

Older Excel versions without TEXTAFTER

TEXTAFTER is available in Microsoft 365 and Excel 2024, but not in some older perpetual Excel releases. In those versions, a formula using SUBSTITUTE can mark the final hyphen, then MID can return everything after it. With the source text in A2 and a hyphen delimiter, use =IFERROR(MID(A2,FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,LEN(A2)),A2).

For order-east-blue, that older-version formula returns blue. It counts the hyphens, replaces the last one with a marker character, locates the marker, and returns the remaining characters. If there is no hyphen, the IFERROR fallback returns the original text. The formula assumes the source text does not already contain the marker character generated by CHAR(1), a control character that is unlikely in normal text but could occur in unusual imported data.

The older formula is harder to read and maintain than TEXTAFTER. If you use it in a shared workbook, add a short note explaining the delimiter and the marker logic. If the data has multiple possible separators or complex rules, consider using a helper column or Power Query rather than turning one cell formula into an opaque parsing routine.

Choose the right formula for the job

  • Last part after a repeated separator: Use TEXTAFTER with -1, such as =TEXTAFTER(A2,"/",-1) for the text after the final slash.
  • Last few characters, regardless of separators: Use RIGHT with the required count, such as =RIGHT(A2,3).
  • Last word in a consistently space-separated phrase: Use TEXTAFTER with a space and -1.
  • Older Excel without TEXTAFTER: Use a compatible SUBSTITUTE-based formula, or split the task into helper steps that are easier to inspect.
  • Data that needs repeatable cleanup and reshaping: Consider Power Query, especially when the same import must be processed regularly.

TEXTAFTER also accepts a multi-character delimiter. If the final section follows a double colon, for example, use =TEXTAFTER(A2,"::",-1). The delimiter must match the characters in the data. A hyphen, en dash, and em dash look similar but are different characters, so a formula searching for one will not automatically match the others.

Common problems to check

If the formula returns an error, first confirm that the delimiter appears exactly as typed and that the text is in the cell the formula references. A copied value may use a different dash, slash, or type of space than expected. If the formula returns too much text, the chosen delimiter may not be the true separator. If it returns only part of the desired value, check whether that value itself contains the delimiter.

Excel formulas use commas between arguments in the examples here. Some regional settings use semicolons instead, so Excel may require semicolons when you enter a formula. If Excel rejects an otherwise valid formula, check the list separator used by your Excel settings. The function name and the double quotation marks around text delimiters remain part of the formula.

Another frequent misconception is that “last” always means the final word. It means the final occurrence of the specified delimiter when you use TEXTAFTER with -1. If a product description contains hyphens inside the product name, extracting after the last hyphen may not identify the intended category. Confirm that the delimiter rule matches the structure of your actual data before applying a formula to a full column.

For a formula that works in Microsoft 365 on Windows, the same TEXTAFTER formula is available in Microsoft 365 for Mac and Excel for the web, subject to the account’s Excel feature availability. The ribbon layout can differ across platforms, but entering the formula in a cell works the same way. Older Excel editions may not recognize TEXTAFTER, which is why the SUBSTITUTE alternative is useful for compatibility.

Frequently Asked Questions

How do I extract everything after the last dash in Excel?
With the string in A2, use =TEXTAFTER(A2,"-",-1). The negative third argument makes Excel find the final hyphen, then return the text after it.

How do I get the last word in a cell?
With the sentence in A2 and ordinary spaces between words, use =TEXTAFTER(A2," ",-1). If your data includes irregular spacing, clean it first or check the result for tabs and special spaces.

How do I return the last four characters?
With the text in A2, use =RIGHT(A2,4). This takes four characters from the right whether or not the string contains a delimiter.

Can TEXTAFTER extract a file extension?
Yes. With filenames in A2, use =TEXTAFTER(A2,".",-1) to get the text after the final period. A filename with no period needs a fallback or error-handling formula.

Why does TEXTAFTER return an error?
The requested delimiter may not occur in the cell, or it may differ from the character in the formula. Use TEXTAFTER’s if_not_found argument or IFERROR if missing delimiters are expected, and inspect unusual dashes and whitespace.

What if my Excel version does not recognize TEXTAFTER?
TEXTAFTER requires Microsoft 365 or Excel 2024. In older versions, use the SUBSTITUTE, FIND, and MID approach shown above, or use a helper column to make the extraction easier to maintain.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.