How to Extract Text from the End of a String Using the RIGHT Function in Excel

When you import data from a legacy database into Microsoft Excel, the resulting text strings are often combined in ways that make them impossible to analyze. For example, you might have a column containing a massive string like “Transaction_Approved_ID45992,” and you desperately need to extract just that final 5-digit ID number to run a VLOOKUP against another table. Instead of manually retyping thousands of numbers, you can automate the extraction process using the RIGHT function.

How the RIGHT Function Works

The RIGHT function is a simple text manipulation tool. You point it at a specific cell, tell it exactly how many characters you want to keep, and it will count backward from the extreme right edge of the text string, slicing off everything on the left side.

The syntax is: =RIGHT(text, [num_chars])

  • text: The cell containing the original, messy data string (e.g., A2).
  • num_chars: The exact number of characters you want to extract, counting from the right side.

How to Extract a Fixed Number of Characters

If your data follows a strictly uniform pattern—for example, if every single transaction ID in your 5,000-row spreadsheet always ends in exactly 5 digits—the formula is incredibly easy to deploy.

  1. Create a new column next to your data (e.g., Column B).
  2. In cell B2, type: =RIGHT(A2, 5)
  3. Press Enter. If cell A2 contained “Transaction_Approved_ID45992”, cell B2 will instantly strip away the text and output only “45992”.
  4. Double-click the Fill Handle (the small green square in the bottom-right corner of cell B2) to instantly copy the formula down all 5,000 rows.

Dynamic Extraction with FIND and LEN

The basic RIGHT function fails if the data length is unpredictable. If one cell ends in a 5-digit ID (“45992”) but the next cell ends in a 9-digit ID (“998822331”), a hardcoded =RIGHT(A2, 5) will truncate the longer ID, destroying your data.

To extract dynamic lengths, you must combine RIGHT with the LEN (length) and FIND functions. Assuming every ID number is separated by an underscore (_), you can instruct Excel to find that underscore and extract everything to the right of it, regardless of how long it is.

=RIGHT(A2, LEN(A2) - FIND("_", A2))

This advanced formula calculates the total length of the string, finds the mathematical position of the underscore, subtracts the two, and passes that exact, perfect character count back to the RIGHT function, ensuring every single ID is extracted flawlessly, no matter how many digits it contains.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.