Hi all,
Please find below some code that I've pulled together.
I have 2 questions:
1. What I would like to see happen is that when an invalid date is entered that after the error message pops up is that the code resumes from where the user is asked to enter the date details. How can I ge this to work? I thought GoTo 0 should do it but it didn't work.
2. When the month is entered by the user it errors unless the month is added in upper case. Is there a way that I can set it as not being case sensitive?
I would be very grateful for any help that anyone can give me.
Thanks
Sub DATA()
Dim Month As Variant
Dim Year As Variant
Dim Day As Variant
Year = Application.InputBox("ENTER THE YEAR AS YYYY)
Month = Application.InputBox("ENTER THE MONTH AS MMM)
Day = Application.InputBox("ENTER THE Day AS DD)
Sheets("DATA ENTRY ").Select
Range("B14").ClearContentsIf YEAR = "2009" Then
Range("B14") = "Y1"
ElseIf YEAR= "2010" Then
Range("B14") = "Y2"
ElseIf YEAR= "2011" Then
Range("B14") = "Y3"
ElseIf YEAR= "2012" Then
Range("B14") = "Y"
Else: MsgBox ("PLEASE ENTER VALID DATE")
Exit Sub
End If
Please find below some code that I've pulled together.
I have 2 questions:
1. What I would like to see happen is that when an invalid date is entered that after the error message pops up is that the code resumes from where the user is asked to enter the date details. How can I ge this to work? I thought GoTo 0 should do it but it didn't work.
2. When the month is entered by the user it errors unless the month is added in upper case. Is there a way that I can set it as not being case sensitive?
I would be very grateful for any help that anyone can give me.
Thanks
Sub DATA()
Dim Month As Variant
Dim Year As Variant
Dim Day As Variant
Year = Application.InputBox("ENTER THE YEAR AS YYYY)
Month = Application.InputBox("ENTER THE MONTH AS MMM)
Day = Application.InputBox("ENTER THE Day AS DD)
Sheets("DATA ENTRY ").Select
Range("B14").ClearContentsIf YEAR = "2009" Then
Range("B14") = "Y1"
ElseIf YEAR= "2010" Then
Range("B14") = "Y2"
ElseIf YEAR= "2011" Then
Range("B14") = "Y3"
ElseIf YEAR= "2012" Then
Range("B14") = "Y"
Else: MsgBox ("PLEASE ENTER VALID DATE")
Exit Sub
End If