Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Getting Rid of Everything Except Numbers.
by Allen Wyatt
(last updated June 21, 2018)
Linda has a column that contains alpha and numeric characters. She needs to retain the numeric characters and delete the alpha ones. For example, a cell may contain 10003E111 and she wants to end up with 10003111.
There are a few ways you can approach this problem. Before proceeding with any solution, however, you should make sure that you aren't trying to change something that isn't really broken. For instance, you'll want to make sure that the "E" that appears in the number isn't part of the format of the number—in other words, a designation of exponentiation. If it is, then you don't really want to remove the character because it will end up changing the nature of the underlying number.
If you determine that the characters aren't part of the number's format, then you can first try using formulas to remove the alpha characters. If the values you want to change are in column A, you could enter the following (very long) formula in column B:
=MID(A1,MATCH(TRUE,ISERROR(1*MID(A1,ROW(INDIRECT ("1:"&LEN(A1))),1)),0),-MATCH(TRUE,ISERROR(1*MID (A1,ABS(ROW(INDIRECT("1:"&LEN(A1)))-LEN(A1)-1),1)) ,0)+LEN(A1)+2-MATCH(TRUE,ISERROR(1*MID(A1,ROW (INDIRECT("1:"&LEN(A1))),1)),0))
Make sure you enter this as an array formula by pressing Ctrl+Shift+Enter. Then enter the following into column C:
The result is that column C contains the values from column A, without the alpha characters. You could use Paste Special to copy the information from column C to another column so that you end up with actual values instead of formula results.
This approach may work great for short-term use on a single workbook, but if you need to do this sort of data processing more often then you will want to create a user-defined function to do the processing. Here's an example:
Function OnlyNums(sWord As String) Dim sChar As String Dim x As Integer Dim sTemp As String sTemp = "" For x = 1 To Len(sWord) sChar = Mid(sWord, x, 1) If Asc(sChar) >= 48 And _ Asc(sChar) <= 57 Then sTemp = sTemp & sChar End If Next OnlyNums = Val(sTemp) End Function
You use this function by calling it from within a worksheet cell:
The function returns a numeric value. If you want to create an even shorter macro to do the processing, consider the following:
Function StripChar(aText As String) Dim I As Integer StripChar = "" For I = 1 To Len(aText) aChar = Mid(aText, I, 1) Select Case aChar Case "0" To "9" StripChar = StripChar & aChar End Select Next End Function
To use this function, use either of the following in your worksheet:
The first returns a text string consisting of the digits, the second returns the numeric version of that string.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3840) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Getting Rid of Everything Except Numbers.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Need to make sure that information entered in a worksheet is always in a given unit of measurement? It's not as easy of a ...Discover More
As you are entering data in a worksheet, Excel can monitor what you type and make corrections for common mistakes. One ...Discover More
We all make mistakes. Fortunately, Excel makes it rather easy to undo your makes, right after you make them.Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.