Worksheet_Change Event Monitoring a Range

ljrezn

New Member
Joined
Jun 27, 2011
Messages
15
I have been able to successfully trigger the Worksheet_Change Event by monitoring one target cell, but how would I write the code if I want the Event to run anytime a cell in a given range is changed?

This is what i tried, but I get an error that says, "Compile Error: Argument not Optional"
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True
On Error GoTo Choice
 
Choice: Application.EnableEvents = False
    On Error GoTo Reenable
        If Target.Range = "B16:G49" Then
             Call Macro1
        End If
Reenable: Application.EnableEvents = True
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo Reenable
Application.EnableEvents = False
On Error GoTo Reenable
If Not Intersect(Target, Range("B16:G49")) Is Nothing Then
     Call Macro1
End If
Reenable:
Application.EnableEvents = True
End Sub
 
Upvote 0
You are welcome. Actually line 2 is unnecessary, it should be

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Reenable
Application.EnableEvents = False
On Error GoTo Reenable
If Not Intersect(Target, Range("B16:G49")) Is Nothing Then
     Call Macro1
End If
Reenable:
Application.EnableEvents = True
End Sub
 
Upvote 0
Thanks. Ya I caught that. For some reason though my version of excel the events are always false, so it errors and the code never runs. So I added the additional statement in my original version up top and now it runs everytime consistently.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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