G
Guest
I would like some help with some efficient VBA code to check to see if a date
that is being input (wkMonth) is outside of the fiscal year (July-June) of
the minimum date that has already been inputted (minMonth). I have some code
that works but I have to repeat a block of code 4 times so I am hoping there
is a more efficient way to code this where I will only have to repeat my
result block once or twice.
Thanks!
BEGIN CODE-----------------------
Select Case Month(wkMonth)
Case 1 To 6
If Month(minMonth) > 6 Then
If Year(wkMonth) <> Year(minMonth) + 1 Then
MsgBox "You can't do this"
Exit Sub
End If
ElseIf Year(wkMonth) <> Year(minMonth) Then
MsgBox "You can't do this"
Exit Sub
End If
Case 7 To 12
If Month(minMonth) < 7 Then
If Year(wkMonth) <> Year(minMonth) - 1 Then
MsgBox "You can't do this"
Exit Sub
End If
ElseIf Year(wkMonth) <> Year(minMonth) Then
MsgBox "You can't do this"
Exit Sub
End If
End Select
END CODE------------------------------------
that is being input (wkMonth) is outside of the fiscal year (July-June) of
the minimum date that has already been inputted (minMonth). I have some code
that works but I have to repeat a block of code 4 times so I am hoping there
is a more efficient way to code this where I will only have to repeat my
result block once or twice.
Thanks!
BEGIN CODE-----------------------
Select Case Month(wkMonth)
Case 1 To 6
If Month(minMonth) > 6 Then
If Year(wkMonth) <> Year(minMonth) + 1 Then
MsgBox "You can't do this"
Exit Sub
End If
ElseIf Year(wkMonth) <> Year(minMonth) Then
MsgBox "You can't do this"
Exit Sub
End If
Case 7 To 12
If Month(minMonth) < 7 Then
If Year(wkMonth) <> Year(minMonth) - 1 Then
MsgBox "You can't do this"
Exit Sub
End If
ElseIf Year(wkMonth) <> Year(minMonth) Then
MsgBox "You can't do this"
Exit Sub
End If
End Select
END CODE------------------------------------