finding numbers
On Mon, 22 Sep 2008 13:23:01 -0700, johnrb7865
wrote:
Hi, does anyone know how I would pull numbers out of a string of text? For
example, the text: Prepare Culvert Pipe (30 Inch), I need a formula to
display just the "30". The text strings will vary so I cannot use MID to pull
out text at certain spots. Any thoughts?
Thanks,
John
If the value will be the first integer in the string, then:
==========================
Option Explicit
Function Nums(str As String) As Double
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "\d+"
If re.test(str) = True Then
Set mc = re.Execute(str)
Nums = mc(0).Value
End If
End Function
===========================
If the value is might be a decimal number or a fraction, then we would need to
change re.pattern.
--ron
|