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.

Getting Rid of Everything Except Numbers

by Allen Wyatt
(last updated January 5, 2015)

8

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:

=SUBSTITUTE(A1,B1,"")

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:

=OnlyNums(A1)

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:

=STRIPCHAR(A1)
=VALUE(STRIPCHAR(A1))

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.

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

Periodically Delete TMP Files

After using Word for a while, you may notice some "litter" of unused files on your hard drive. This tip explains how those ...

Discover More

Creating New Windows

If you need to look at different parts of the same worksheet at the same time, the answer is to create windows for your data. ...

Discover More

Opening a Workbook and Suppressing Automatic Macros

Want to stop Excel from running any automatic macros that may be stored with a workbook? Here's how to do it.

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Limiting Entry of Prior Dates

Want to establish a "bottom limit" on what dates can be entered in a cell? This tip presents two different ways you can limit ...

Discover More

Forcing Editing to Be Done in a Cell

Excel allows you to edit your cell contents in two places. What if you want to limit where editing occurs, so it can only be ...

Discover More

Deleting All Names but a Few

Want to get rid of most of the names defined in your workbook? You can either delete them one by one or use the handy macro ...

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 nine minus 5?

2016-03-11 06:54:32

Michael (Micky) Avidan

@Wes,
Try: =SUBSTITUTE(A1,"qwert",)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-03-11 06:51:03

Michael (Micky) Avidan

@Yuki,
In cell Q1 type:
=IF(LEFT(P1,3)="Inv",SUBSTITUTE(P1,LEFT(P1,FIND("||",SUBSTITUTE(P1," ","||",2))),),P1)
and copy down along to cell P300.
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-03-10 14:57:50

Wes

Great tip! How would I leave a specific character that is part of the number formatting. For example. I have numbers with a "." which I would like to keep

"000.000qwert0.000 qwert"

I'd like to remove the qwert and keep the "."


2015-05-19 14:17:15

Yuki

In a data like this in column P, 300 lines:


Payment Type
Temp Living (10/24/14 - 12/24/14) Cable
Temp Living (10/24/14 - 12/24/14) Utilities
Inv I-333-9677 3 Day Bundle Home Finding
Inv 999994 Temp Living (09/09/99 - 09/89/99) Lodging (89 Days)
Temp Living (01/13/15 - 02/21/15) Car Rental (49 Days)
Inv 90098076 Household Sea Shipment
Inv 90098076 Household Sea Valuation
Inv 99490000487439 Temp Living (08/09/99 - 08/88/99) Lodging (84 Days)
Inv I-333-4899 8 Day Bundled Service
Inv 999676 Temp Living (09/09/99 - 09/39/99) Lodging (39 Days)
Inv 9987 Immigration (Charoensukmongkol) Visa App
Inv 9987 Immigration (Dependent)
Househumting Trip (03/23/15 - 03/27/15) Meals
Househunting Trip (03/23/15 - 03/26/15) (5 Days)
Househunting Trip (03/23/15 - 03/27/15) Car Rental (4 Days)
Househunting Trip (03/23/15) Telephone/Sim Card
Househunting Trip (03/27/15) Rental Car Gas
Visa / Immigration (03/12/15) Fam
Visa Blanket-L Fraud (03/12/15) EE
Visa Fee (02/26/15)
Inv 90009803 Household Sea Shipment
Inv 90009803 Household Sea Valuation
Inv 999674 Temp Living (09/09/99 - 09/07/99) Lodging (97 Days)
School Tuition Deposit 2015-2016 Cedrick
School Tuition Deposit 2015-2016 Margaret
School Deposit (03/04/15) Matriculation Thais
School Deposit (02/09/15) Tuition Oscar
Inv 90006686 Household (Jan-March 8099) Perm Storage
Inv 90006686 Household (Nov-Dec 8094) Perm Storage
Inv 90006686 Household (Jan-March 8099) Perm Valuation
Inv 90006686 Household (Nov-Dec 8094) Perm Valuation
Inv 90006686 Household into Perm Storage
within one column I need to remove the Invoce number, basically to replace "Inv xxxxxxxx" by nothing and each invoice number is different. Can't remove the date tho so replacing numbers by ""is not a good tip. Any help on this?


2015-01-06 13:30:15

Willy Vanhaelen

I always prefer simple UDF's instead of complicated long formulas. Here is a very simple UDF for the job:

Function StripChar(S As String)
Dim X As Integer, C As String
For X = 1 To Len(S)
C = Mid(S, X, 1)
If IsNumeric(C) Then StripChar = StripChar & C
Next
End Function


2015-01-06 10:09:56

Michael (Micky) Avidan

I believe the following "short" Array-Formula will accomplish the task:
=SUM(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW($1:$99),1))*ROW($1:$99),),ROW($1:$99))+1,1)*10^ROW($1:$99)/10)
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2015-01-05 08:58:44

Magnus Eriksen

Hi Brian Schroeder,

You might already have solved your issue, didn't see the comment until now.

Would it would be a possibility for you to multiply the cell value with 1 (AD1*1)? If the cell contains an alpha character, this would render "0".


2014-05-22 13:02:12

Brian Schroeder

Hi, I have two columns (AD and AE) which contain either numbers OR alpha characters. I want to run a macro to replace any alpha characters with 0. I've tried many solutions to similar (but not exact) issues, but cannot get the desired results. Any help would be greatly appreciated!


This Site

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.

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.