I have a macro which asks the user to input several values and then I need to test and see if they are valid. Here is the current code that I have
Dim CutDate As Date
Dim CutDay, CutMunth, CutYear, CutHour, CutMinute As Integer
CutMonth:
CutMonth = Application.InputBox("Please enter the month of the DSS cut (1 to 12)")
If CutMonth < 1 Or CutMonth > 12 Then GoTo CutMonth
CutDay:
CutDay = Application.InputBox("Please enter the day of the DSS cut (1 to 31)")
If CutDay < 1 Or CutDay > 31 Then GoTo CutDay
CutYear:
CutYear = Application.InputBox("Please enter the year of the DSS cut (4 digits)")
If CutYear <= 1000 Or CutYear >= 9999 Then GoTo CutYear
CutHour:
CutHour = Application.InputBox("Please enter the hour of the DSS cut (0 to 23)")
If CutHour < 0 Or CutHour > 23 Then GoTo CutHour
CutMinute:
CutMinute = Application.InputBox("Please enter the minute of the DSS cut (0 to 59)")
If CutMinute < 0 Or CutMinute > 59 Then GoTo CutMinute
CutDate = DateSerial(CutYear, CutMonth, CutDay) + TimeSerial(CutHour, CutMinute, 0)
The issue I am having is that if the user enters a decimal it will be accepted. Also I want to be able to cancel the input, i.e. if the user presses cancel the input box will disappear.
Can anyone please offer me any suggestions to improve the code?
Bookmarks