Hi,
I have made a UserForm to collect data and based on the user input want to check whether two dates are consecutive years. Here is the code:
After above code i want to check whether dates in E12 and E14 are two dates wherein only year has changed (the DD/MM will always be 31/03 only YYYY can change)
For e.g. E12 = 31/03/2022 and E14=31/03/2021
If they are consecutive years then E13=E14 else E13=E14 + 1 year (i.e. 31/03/YYYY + 1 YYYY)
After that
Can someone please help me with the code for the middle part i.e. to check if dates are two consecutive years or not.
I have made a UserForm to collect data and based on the user input want to check whether two dates are consecutive years. Here is the code:
VBA Code:
Private Sub Submit_Click()
Dim ws As Worksheet
Set ws = Worksheets("MasterData")
ws.Range("E12").Value = CurrentDate.Value 'this date will be in 31/03/YYYY format
ws.Range("E14").Value = PrevDate.Value 'this date will be in 31/03/YYYY format
After above code i want to check whether dates in E12 and E14 are two dates wherein only year has changed (the DD/MM will always be 31/03 only YYYY can change)
For e.g. E12 = 31/03/2022 and E14=31/03/2021
If they are consecutive years then E13=E14 else E13=E14 + 1 year (i.e. 31/03/YYYY + 1 YYYY)
After that
VBA Code:
If ws.Range("E14").Value = ws.Range("E13").Value Then
Else
Sheets("StartUp1").Visible = True
Sheets("StartUp").Visible = False
Sheets("Data1").Visible = True
Sheets("Data").Visible = False
End Sub
Can someone please help me with the code for the middle part i.e. to check if dates are two consecutive years or not.