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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
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)
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,808
Members
448,990
Latest member
rohitsomani

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
Back
Top