I do not ever use isNumeric to see if a text is a number, isnumeric is
unreliable for this purpose
I use regular expressions in this way or adapting:
Public Function RE_Function( _
Testo As String, sPattern As String) As Boolean
'Funzione generica che utilizza le
'Espressioni regolari
Dim RE As Object
Set RE = CreateObject("VBScript.RegExp")
RE.Global = True
RE.Pattern = sPattern
RE_Function = RE.test(Testo)
End Function
Sub test_isNumeric()
Dim sPatternIsLong As String
Dim sPatternIsDouble As String
Dim sTest As String
sPatternIsLong = "^" & _
"(0|[+-]?(?!0)" & _
"\d+)$"
sPatternIsDouble = "^(0|[+-]?" & _
"((?!0)\d+([.]\d+)?" & _
"|[0]+([.]\d+)?))$"
Debug.Print IsNumeric("123..456") 'true
Debug.Print RE_Function("123..456", sPatternIsLong) 'false
Debug.Print RE_Function("123..456", sPatternIsDouble) 'false
Debug.Print IsNumeric("123,45") 'true
Debug.Print RE_Function("123,45", sPatternIsLong) 'false
Debug.Print RE_Function("123,45", sPatternIsDouble) 'false
Debug.Print IsNumeric("0123") 'true
Debug.Print RE_Function("0123", sPatternIsLong) 'false
Debug.Print RE_Function("0123", sPatternIsDouble) 'false
End Sub
regards
r
http://excelvba.altervista.org/blog/...ione-Form.html
"Alfredo_CPA" wrote:
I'm using excel 2003
I have an input box that allows the suer to enter a variable.
I need a code that validates the "type of entry" the user types. I.e. if the
input is a number I need the code to do an specific action, but if the user
types a "legend/word", I want the code to do a different action.
My problem is not with the if structure, my problem is the code to validate
the type of entry...
--
thanks