Multiple Worksheet_Change events issue

hgfantomas

New Member
Joined
Jul 2, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
So, I have two rows where I enter a date (row 9 and row 12 - for columns B thru L). I have a VBA macro that compares it to the date in corresponding column in row 5. If row 5 is older than input date, then the message box pops up. I am able to do this for row 9 but cannot seem to add the trigger for row 12. Any help? See below for my code so far.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim r2 As Range, s2 As String

If Intersect(Target, Range("B5:L9"), Range("B5:L12")) Is Nothing Then Exit Sub
For Each r2 In Target.Rows
    If Intersect(Range("B5:L5"), r2.EntireColumn).Value < Intersect(Range("B9:L9"), r2.EntireColumn).Value And Intersect(Range("B9:L9"), r2.EntireColumn) <> vbNullString Then s2 = s2 & ", " & r2.Address
Next r2
If s2 <> vbNullString Then MsgBox "Entry Date Past Due; Comment Required", vbOKOnly + vbExclamation

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try changing this line:

VBA Code:
If Intersect(Target, Range("B5:L9"), Range("B5:L12")) Is Nothing Then Exit Sub
to
VBA Code:
If Intersect(Target, Range("B5:L9, B5:L12")) Is Nothing Then Exit Sub
and change the rest of your code accordingly.

BUT B5:L9 is a subset of B9:L12 so the B5:L9 is redundant. Since you're only trying to catch changes in rows 9 and 12 then I think what you actually need is
VBA Code:
If  Intersect(Target, Range("B9:L9, B12:L12")) Is Nothing Then Exit Sub
 
Upvote 0
Solution
Try changing this line:

VBA Code:
If Intersect(Target, Range("B5:L9"), Range("B5:L12")) Is Nothing Then Exit Sub
to
VBA Code:
If Intersect(Target, Range("B5:L9, B5:L12")) Is Nothing Then Exit Sub
and change the rest of your code accordingly.

BUT B5:L9 is a subset of B9:L12 so the B5:L9 is redundant. Since you're only trying to catch changes in rows 9 and 12 then I think what you actually need is
VBA Code:
If  Intersect(Target, Range("B9:L9, B12:L12")) Is Nothing Then Exit Sub
That worked. thank you
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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