Forum Discussion
Greeny95
Apr 24, 2022Copper Contributor
VBA code message box
Hi all. I need some brains here. I need a VBA code for this action: I want a simple message box to appear (a warning) depending on the choices made by the person who uses this worksheet. For exam...
Greeny95
Apr 29, 2022Copper Contributor
I knew the formula. But I meant the VBA code...
HansVogelaar
Apr 29, 2022MVP
Using the same example as before:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rw As Range
Dim r As Long
If Not Intersect(Range("A2:D20"), Target) Is Nothing Then
For Each rw In Intersect(Range("A2:D20"), Target).Rows
r = rw.Row
If (Range("A" & r).Value = "Antwerp" Or Range("A" & r).Value = "Berlin" Or Range("A" & r).Value = "Boston") And _
(Range("B" & r).Value = "blue" Or Range("B" & r).Value = "green" Or Range("B" & r).Value = "red") And _
Range("C" & r).Value = "Yes" And Weekday(Range("D" & r)) = vbSunday Then
MsgBox "Incorrect selection in row " & rw.Row, vbExclamation
End If
Next rw
End If
End Sub- Greeny95Apr 29, 2022Copper ContributorThanks a lot, Hans! It works perfect!!!!