Dave wrote:
Hope someone can help!
I have a memo fiels in which there are a few numbers including dates but
what I want to do is extract a number which is 6 figures long. Can anyone
help me?
Thanks Dave
This requires that VB Script be installed. TTBOMK it is installed by
default with Windows >=2000.
Public Function SixDigitNumerals(ByVal vInput As String) As Variant
' assumes VBScript is installed
Dim RE As Object
Dim SDNMatches As Object
Dim SDN As Variant
Dim SDNS As String
Set RE = CreateObject("VBScript.RegExp")
With RE
.Global = True
.Pattern = "(\b|\D)\d{6}(\D|\b)"
End With
Set SDNMatches = RE.Execute(vInput)
For Each SDN In SDNMatches
SDNS = SDNS & "," & Mid$(SDN, 2, 6)
Next SDN
SDNS = Replace(SDNS, ",", "", , 1)
SixDigitNumerals = Split(SDNS, ",")
End Function
Sub test()
Dim s As Variant
Dim ss As Variant
s = SixDigitNumerals("a666666da55555a7777777g000000")
For Each ss In s
Debug.Print ss
Next ss
End Sub
It returns 666666 and 000000
It does not return the five digit 55555 nor the seven digit 7777777. It
could be adjusted according to your needs.
The function is not mature. I dashed it off while waiting for supper,
so it's only very slightly advanced beyond air code.
Maybe it needs the two objects to be released. I tend not to do this
unless VBA forces me to.
I wrote this in Google's TextBox ... at times it went nuts and showed
everything several times ... I hope it posts OK.