AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 1,822
- Office Version
- 2019
- 2016
- Platform
- Windows
Any idea what is wrong please?
My test is
debug.print numbersonly2("J91f91")
This results in an empty string. By altering the pattern I can get some numbers returned, but not all.
Unsure too, if it should return a string, or a different data type. Or maybe it doesn't matter.
Thanks
Code:
Function NumbersOnly2(loc) As String
Dim RE As Object, REMatches As Object
Set RE = CreateObject("vbscript.regexp")
RE.Pattern = "^[0-9]*$"
If (RE.Test(loc) = True) Then
Set REMatches = RE.Execute(loc)
NumbersOnly2 = REMatches(0)
End If
Set REMatches = Nothing
Set RE = Nothing
End Function
My test is
debug.print numbersonly2("J91f91")
This results in an empty string. By altering the pattern I can get some numbers returned, but not all.
Unsure too, if it should return a string, or a different data type. Or maybe it doesn't matter.
Thanks