How do I check if a string is either a one digit number OR a two digit number and otherwise return false
?
How about:
Function OneOrTwo(i As Integer) As Boolean
Dim objRegEx As Object
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = "^\d{1,2}$"
OneOrTwo = objRegEx.Test(i)
End Function
See: http://msdn.microsoft.com/en-us/library/ms974570.aspx
You can also do this using VBA LIKE:
Function OneOrTwo(Digits As Variant) As Boolean
OneOrTwo = Digits Like "#" Or Digits Like "##"
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With