I want to do VBA code as below.
Here is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Range("L4") >= 4 Then Exit Sub
Else
msg = MsgBox("Application takes at least 4-7 working days", vbOKOnly, "Reminder")
Range("J4").Select
Selection.ClearContents
msg = MsgBox("Please choose another date", vbOKOnly)
End If
End sub
First check to see if the Worksheet_Change
Target
is the date cell that the user is updating (J4). If it is, check L4
and pop your message box. Lastly turn events back on so it can trigger again next time there is a change.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Range("J4"), Target) Is Nothing Then:
If Range("L4").Value < 4 Then
msg = MsgBox("Application takes at least 4-7 working days", vbOKOnly, "Reminder")
Range("J4").ClearContents
meg = MsgBox("Please choose another date", vbOKOnly)
End If
End If
Application.EnableEvents = True
End Sub