You may be interested in this UDF. It can be used in spreadsheet formulas.
getFirstNumber returns the number matching the first numeral in a string
getFirstNumber("xx12yy") =12
getfirstnumber("xx1.2yy33")=1.2
Be aware of "-" and "."
getfirstNumber("xx. 3")=.3
getFirstNumber("aa-34")=-34
If the optional second argument (percentCorrection) is set to True, it checks for a "%" anywhere after the first numeral and returns the decimal expression. percentCorretion defaults to False.
getFirstNumber("aa30%") = 30
getFirstNumber("aa30%", False) = 30
getFirstNumber("aa30%", True) = .3
getFirstNumber("bb24xyz12%x",True) = .24
I hope it helps.
Function getFirstNumber(inputString As String, Optional pctCorrect As Boolean) As Double
Dim i As Long
i = 1
Do Until i > Len(inputString) Or Val(Mid(inputString, i)) <> 0
i = i + 1
Loop
getFirstNumber = Val(Mid(inputString, i))
If pctCorrect And InStr(Mid(inputString, i), "%") > 0 Then _
getFirstNumber = getFirstNumber / 100
End Function
Bookmarks