Private Function Min(ByVal valueA As Long, ByVal valueB As Long) As Long
If valueA < valueB Then
Min = valueA
Else
Min = valueB
End If
End Function
Public Function ExtractFirstNumber(ByVal strSourceString As String) As Variant
Dim strNumber As String
Dim l As Long
Dim c As String * 1
Dim i As Long
Dim j As Long
Dim last As Long
l = Len(strSourceString)
For i = 1 To l
c = Mid(strSourceString, i, 1)
If IsNumeric(c) Or ((c = "." Or c = "+" Or c = "-") And IsNumeric(Mid(strSourceString, Min(i + 1, l), 1))) Then
strNumber = c
For j = i + 1 To Len(strSourceString)
c = Mid(strSourceString, j, 1)
If Not IsNumeric(strNumber & c) Then Exit For
strNumber = strNumber & c
Next j
ExtractFirstNumber = CDec(strNumber)
Exit Function
End If
Next i
End Function
|