I have a custom function created to extract integers from a string. This initially worked fine when the strings consisted of a set format of text+integer. Now I have instances where the string consists of integers+text+integers but I only want to capture the first set of integers. I've copied the code for the function below and I'm looking for a way to modify so I can extract the first set of integers from the string.
I've also attached a workbook as an example.
Code
Function GetNum(MyInput As String)
Dim i As Integer
Dim j As Integer
Dim NumOnly As String
'Count total strings of Input
For i = Len(MyInput) To 1 Step -1
If IsNumeric(Mid(MyInput, i, 1)) Then
j = j + 1
NumOnly = Mid(MyInput, i, 1) & NumOnly
End If
If j = 1 Then NumOnly = CInt(Mid(NumOnly, 1, 1))
Next i
GetNum = NumOnly
End Function
Display More