2 conditions in Worksheet_Change sub

BMD44

Board Regular
Joined
Sep 25, 2019
Messages
72
Hello,

I have a requirement where in a message needs to be displayed based on the cell value in the sheet which works as expected which is below.

Now, I need another check and message to be displayed based on a different cell value when the value changes which is the second section of the code that doesn't work. Can anyone please suggest how can we have multiple checks in Worksheet_Change Sub.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$2" Then
        If Target.Value = "Yes" Then
            MsgBox "Check required."
        ElseIf Target.Value = "No" Then
            MsgBox "Check not required"
        End If
    End If

  If Target.Address = "$E$2" Then
        If Target.Value = "Yes" Then
            MsgBox "Total > 500"
        ElseIf Target.Value = "No" Then
            MsgBox "Total < 500"
        End If
    End If
   
End Sub
 
See if doing it this way works for you:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$2" Then
        If Target.Value = "Yes" Then
            MsgBox "Check required."
        ElseIf Target.Value = "No" Then
            MsgBox "Check not required"
        End If
    End If

  If Not Intersect(Target, Range("E6:E500")) Is Nothing Then
        If Range("E2").Value = "Yes" Then
            MsgBox "Total > 50000"
        ElseIf Range("E2").Value = "No" Then
            MsgBox "Total < 50000"
        End If
    End If
   
End Sub
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,215,491
Messages
6,125,110
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top