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!
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

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,494
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,537
Messages
5,572,782
Members
412,484
Latest member
deezina07
Top