PDA

View Full Version : [SOLVED:] Using multiple if criteria in VBA



samabert
10-01-2013, 11:30 AM
Hi there,

I have 3 criteria I need to test in VBA in excel.
I need to see if range B5:I31 is equal or greater than B3 and when test is true popup a message box.

The next check is in range B35:I61 with test value in B33

The third check is in range B66:I91 with test value in B64

At this point this is what I have, the first test range B5:I31 works and when the value in this range is equal or greater than the value in B3 the message box popsup.

How you do you write the code so the two other if statements works like the first?

Thank you in advance

Marc

p45cal
10-01-2013, 11:45 AM
try:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LimitReached As Boolean 'initialises to FALSE.
If Not Intersect(Target, Range("B5:I31")) Is Nothing Then
If Target.Value >= Range("B3").Value Then LimitReached = True
End If
If Not Intersect(Target, Range("B35:I61")) Is Nothing Then
If Target.Value >= Range("B33").Value Then LimitReached = True
End If
If Not Intersect(Target, Range("B66:I91")) Is Nothing Then
If Target.Value >= Range("B64").Value Then LimitReached = True
End If
If LimitReached Then MsgBox "PRV Limit Exposure Reached", vbOKOnly, "Alert"
End Sub

samabert
10-01-2013, 12:12 PM
That worked!
Thank you very much.