Function to test an Unsign Whole Number: (cannot be simpler)
'Simplest' IsNumer() function for all possible combination cases: Please test and comment.Code:Function IsDigits(ByVal Num As Variant) As Boolean IsDigits = (Len(Num) > 0) And (Num Like String(Len(Num), "#")) End Function
You need to change to match with your local setting such as . , $
Code:Function IsNumber(var As Variant, Optional AllowDot As Boolean, _ Optional AllowComma As Boolean, _ Optional AllowSgnL As Boolean, _ Optional AllowSgnR As Boolean, _ Optional AllowPars As Boolean, _ Optional AllowCurr As Boolean, _ Optional AllowSpcL As Boolean, _ Optional AllowSpcR As Boolean, _ Optional AllowSci As Boolean, _ Optional AllowHex As Boolean, _ Optional AllowOct As Boolean) As Boolean If Not IsNumeric(var) Then ElseIf AllowDot > -UBound(Split(var, ".")) Then '-- see Note below ElseIf Not AllowComma And var Like "*,*" Then '-- thousand seperator ElseIf Not AllowSgnL And var Like "[-+]*" Then '-- leading sign ElseIf Not AllowSgnR And var Like "*[-+]" Then '-- trailing sign ElseIf Not AllowPars And var Like "*(*" Then '-- parentheses as negative ElseIf Not AllowCurr And var Like "*$*" Then '-- currency ElseIf Not AllowSpcL And var Like " *" Then '-- leading spaces ElseIf Not AllowSpcR And var Like "* " Then '-- trailing spaces ElseIf Not AllowSci And var Like "*[DE]*" Then '-- Scientific ElseIf Not AllowHex And var Like "*H*" Then '-- Hex ElseIf Not AllowOct And var Like "*O*" Then '-- Oct Else IsNumber = True End If End FunctionCode:'-- Note: ElseIf AllowDot > -UBound(Split(var, ".")) Then '-- equivalent with ' Dim d As Integer ' d = UBound(Split(var, ".")) '-- count number of dots ' ... ... ' ElseIf Not AllowDot And d > 0 Then ' ElseIf AllowDot And d > 1 Then




Reply With Quote