S
Student
Good Morning All...Your help is greatly appreciated!
I am in the process of setting up the Data Validation using Custom option to
validate if the right zip code is entered. the user has the option to either
enter 5 or 9 digit zip code with the option to enter either space or "-" .
here is my code
Function isValidZip(zip As String) As Boolean
Dim Punct, TempZIP As String
If InStr(1, zip, " ") > 1 Then
Punct = " "
ElseIf InStr(1, zip, "-") > 1 Then
Punct = "-"
End If
If InStr(1, zip, Punct) > 1 Then
TempZIP = Left(zip, InStr(1, zip, Punct) - 1)
TempZIP = TempZIP & Right(zip, Len(zip) - InStr(1, zip, Punct))
zip = TempZIP
End If
If Len(zip) = 5 Or Len(zip) = 9 Then
isValidZip = True
Else
isValidZip = False
End If
If Not CInt(zip) Then
MsgBox "Invalid Zip code, Please Try again "
End If
End Function
the problem is I want to check if what they entered is a number or not, if
not show error message. As shown below
If Not CInt(TempZIP) Then
MsgBox "Invalid Zip code, Please Try again "
End If
the CInt returns application error or type mismatch
is there other type of function that i can use or create to check if data
enterd is a number and if not then show error message ?
thank you
I am in the process of setting up the Data Validation using Custom option to
validate if the right zip code is entered. the user has the option to either
enter 5 or 9 digit zip code with the option to enter either space or "-" .
here is my code
Function isValidZip(zip As String) As Boolean
Dim Punct, TempZIP As String
If InStr(1, zip, " ") > 1 Then
Punct = " "
ElseIf InStr(1, zip, "-") > 1 Then
Punct = "-"
End If
If InStr(1, zip, Punct) > 1 Then
TempZIP = Left(zip, InStr(1, zip, Punct) - 1)
TempZIP = TempZIP & Right(zip, Len(zip) - InStr(1, zip, Punct))
zip = TempZIP
End If
If Len(zip) = 5 Or Len(zip) = 9 Then
isValidZip = True
Else
isValidZip = False
End If
If Not CInt(zip) Then
MsgBox "Invalid Zip code, Please Try again "
End If
End Function
the problem is I want to check if what they entered is a number or not, if
not show error message. As shown below
If Not CInt(TempZIP) Then
MsgBox "Invalid Zip code, Please Try again "
End If
the CInt returns application error or type mismatch
is there other type of function that i can use or create to check if data
enterd is a number and if not then show error message ?
thank you