View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones[_2_] Norman Jones[_2_] is offline
external usenet poster
 
Posts: 421
Default 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