Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Getting Rid of Everything Except Numbers

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.

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.

Related Tips:

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!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Michael (Micky) Avidan    11 Mar 2016, 06:54
@Wes,
Try: =SUBSTITUTE(A1,"qwert",)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL
Michael (Micky) Avidan    11 Mar 2016, 06:51
@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
Wes    10 Mar 2016, 14:57
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 "."
Yuki    19 May 2015, 14:17
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?
Willy Vanhaelen    06 Jan 2015, 13:30
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
Michael (Micky) Avidan    06 Jan 2015, 10:09
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
Magnus Eriksen    05 Jan 2015, 08:58
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".
Brian Schroeder    22 May 2014, 13:02
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!
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.