Mega Code Archive

 
Categories / VisualBasic Script / Language Basics
 

Validate the users entry

Sub GetValue3()     MinVal = 1     MaxVal = 12     msg = "Enter a value between 1 and 12"     ValidEntry = False     Do         UserEntry = InputBox(msg)         If IsNumeric(UserEntry) Then             If UserEntry >= 1 And UserEntry <= 12 Then                 ValidEntry = True             Else                 msg = "Your previous entry was INVALID."                 msg = msg & "Enter a value between 1 and 12"             End If         End If         If UserEntry = "" Then Exit Sub     Loop Until ValidEntry     ActiveSheet.range("A1").value = UserEntry End Sub