Function GetNum(str As String, num As Integer) As Variant
' Get numbers in string that are at least 3 digits
' - str: string to search
' - num: which number to bring back (1 = first, 2 = second, ...)
Dim arr() As String
Dim i As Long
Dim n As Long
Dim ret As Double
Dim nn As Long
' Split string by spaces and store in an array
arr = Split(str, " ")
' Loop through values in array
For i = LBound(arr) To UBound(arr)
' Count the number of numbers at the beginning of the string
nn = CountNums(arr(i))
' See if three or more numbers
If nn >= 3 Then
' Increment counter
n = n + 1
' See if this is the number you are looking for
If n = num Then
' Record number
ret = Left(arr(i), nn)
' Exit for loop
Exit For
End If
End If
Next i
' See if it found a value
If ret = 0 Then
GetNum = "-"
Else
GetNum = ret
End If
End Function
Function CountNums(str As String) As Long
' Counts the number of numbers at the beginning of a string/word
Dim i As Long
Dim j As Long
Dim n As Long
' Find length of string
j = Len(str)
'
If j > 0 Then
For i = 1 To j
If IsNumeric(Mid(str, i, 1)) Then
n = i
Else
Exit For
End If
Next i
End If
CountNums = n
End Function