How to select numeric characters only?

ophelia

New Member
Joined
Nov 23, 2005
Messages
2
Hi

I need to be able to pull numeric characters only out of a list of names into another column on the same line. The characters are not always in the same position. E.g.

Example 1234
Example of (1234)
Example (3567) & Co
Longer Example of 4567 & Co


Is there a function that I can use to do this?

Advice greatly appreciated!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Here is a custom function. Use it same as any other with something like :-
=getnumeric(A1).
Code:
Public Function GetNumeric(v As Variant) As Variant
    Dim Vstr As String
    Vstr = CStr(v)
    GetNumeric = ""
    For n = 1 To Len(Vstr)
        c = Mid(Vstr, n, 1)
        If IsNumeric(c) Then
            GetNumeric = GetNumeric & c
        End If
    Next
End Function
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Hi, Welcome to the board!

a VBA solution:
Code:
Function ExtractNumbers(ByVal InputString As String) As Variant
Dim iPtr As Integer, iLen As Integer
Dim sChar As String
Dim vResult As Variant
For iPtr = 1 To Len(InputString)
    sChar = Mid$(InputString, iPtr, 1)
    If IsNumeric(sChar) Then vResult = vResult & sChar
Next iPtr
ExtractNumbers = Val(vResult)
End Function

To install, [Alt-F11] Insert / Module & paste above into code window.

Example of use:
Book1
ABCD
1extract 12341234
2zzzz 2345 xxxx2345
3a1b2c3123
4zxcvb0
Sheet1


Formula in B1 & copied down is =ExtractNumbers(A1)
 

ophelia

New Member
Joined
Nov 23, 2005
Messages
2
As I feared, it's a bit more complicated than my limited knowledge but fortunately someone here looked at that and said confidently, "yes, that will work!"

Many thanks!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,808
Messages
5,833,781
Members
430,232
Latest member
Testsubject

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top