Retreiving only numeric values from a string
Hi Alex,
oRegExp.Pattern = "/d"
Should read:
oRegExp.Pattern = "\D+"
and:
Application.Volatile
is unnecessary.
Therefore, replace the suggested function with:
'=============
Public Function NumberOnly( _
sStr As String) As Variant
Dim oRegExp As Object
Set oRegExp = CreateObject("VBScript.RegExp")
With oRegExp
.IgnoreCase = True
.Global = True
oRegExp.Pattern = "\D+"
NumberOnly = .Replace(sStr, vbNullString)
If IsNumeric(NumberOnly) Then _
NumberOnly = CDbl(NumberOnly)
End With
End Function
'<<=============
---
Regards.
Norman
|