Stripping Trailing Letters and Periods

Written by Allen Wyatt (last updated September 12, 2026)

Chris has data in a worksheet that consists, in column A, of text values, such as 5.552A.P or 8X.345.C. There is no pattern within the data, other than values will always end with some combination of periods and letters (A.P and .C in the examples). Chris needs to strip off these trailing characters and return what is before them. He wonders if there is a way to perform this task using a formula.

This is a tricky one, as Chris essentially wants to remove any letters and any periods that may occur after the last digit in a text string. The first thought is that, perhaps, the task can be accomplished by figuring out where the last digit is in the text string and then deleting everything after that. However, Chris said that only trailing letters and periods should be deleted. That means that the string "T54.X;" should not have anything deleted because the last character (the semicolon) should not be deleted, and thus everything before it should remain.

The complexity (or trickiness, if you prefer) means that the best solution for the greatest number of Excel versions will be achieved by using a macro. Before getting to a macro solution, however, consider the following, which will work in Excel 365:

=REGEXREPLACE(A2, "[A-Za-z.]+$", "")

The REGEXREPLACE function uses a pattern to determine what to replace in cell A2. In this case, the pattern is "any number of letters and periods that occur at the end of the text string." The [A-Za-z.] indicates the matchable characters (letters and periods), the plus sign (+) means "any number of the foregoing characters," and the dollar sign ($) means "at the end of the text string." Anything that matches this pattern is replaced with an empty string (""), meaning it is deleted. What is left is what Chris indicates he needs, with no need for a macro.

Which brings us to the macro approach. You can create a user-defined function that will do essentially the same thing:

Function StripSuffix(ByVal Value As String) As String
    Dim J As Long
    Dim ch As String

    For J = Len(Value) To 1 Step -1
        ch = Mid(Value, J, 1)
        If Not (ch Like "[A-Za-z.]") Then
            StripSuffix = Left(Value, J)
            Exit Function
        End If
    Next J
    StripSuffix = ""
End Function

The UDF steps backward through the contents of the cell and, at the first occurrence of something that is not a period or letter, exits the function and returns that truncated string. If the cell is composed of nothing but letters and periods, then the UDF returns an empty string, which is the exact behavior of the REGEXREPLACE function. To use the UDF in your worksheet, use the following:

=StripSuffix(A2)

While the REGEXREPLACE formula requires Excel 365, the UDF approach will work just fine in all modern versions of Excel.

There is one thing to note as a potential gotcha: When I was doing my testing, I typed in the text "ABC....." and expected the REGEXREPLACE formula and the UDF to both return an empty string. They did not. The reason is that when I typed the first three periods, Excel automatically converted them to an ellipsis character—they looked like periods, but were not periods. The string, without my notice, turned into "ABC" followed by an ellipsis character and two additional periods. So, the ellipsis was left in the text string returned by both the formula and the UDF.

The bottom line is that if you don't get the precise results you expect, then you may want to examine what Excel is doing with what you are providing to it.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (14003) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Scanning and Fixing System Files

Is your system running a bit flakey at times? If you think the culprit might be a problem with some of your system files, ...

Discover More

Creating a Header

When preparing your worksheet for printing, you may want to add a header that appears at the top of each page that you ...

Discover More

Switching Editing Location

Excel allows you to edit the contents of a cell in two places--"the cell itself or in the Formula bar. If you want to ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Adding Dashes between Letters

When processing some text data, you may need to perform some esoteric function, such as adding dashes between letters. ...

Discover More

Cell and Name References in COUNTIF

The second parameter of the COUNTIF function is used to specify the criteria to be used when determining what should be ...

Discover More

Working with Imperial Linear Distances

Excel works with decimal values very easily. It is more difficult for the program to work with non-decimal values, such ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.