Run macro if any cell in a named range changes

Ken Russell

New Member
Joined
Sep 8, 2014
Messages
20
I'm tearing my hair out trying to get this to work.

I have a range named Text in a sheet in a workbook. I would like the macro FillComments to run when any cell in that range is changed.

I can't see why the following doesn't work :eek:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target.Addresss = Range("Text")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Call FillComments
Application.EnableEvents = True
End Sub

Any help would be appreciated by this 81 year old :cool:

Cheers,
Ken
 
One last try.

The macro worked perfectly as a stand alone invoked by Ctrl + Shift + c, it also worked using Workbook events Open and also Close. It only fails with the Change event.

Does that give any clues/

Cheers,
Ken
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You could try commenting out the line as shown but I can't see why that line would cause your other code to fail

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("Text")) Is Nothing Then Exit Sub
'Application.EnableEvents = False
Call FillComments
Application.EnableEvents = True
End Sub
 
Upvote 0
You could try commenting out the line as shown but I can't see why that line would cause your other code to fail

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("Text")) Is Nothing Then Exit Sub
'Application.EnableEvents = False
Call FillComments
Application.EnableEvents = True
End Sub

I now reeive this error:

Run-time error '1004':
Method 'Range' of object '_Worksheet' failed.
 
Upvote 0
In that case

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("Dave1")) Is Nothing Then Exit Sub ' or is it Dave2?
'Application.EnableEvents = False
Call fillcomments
Application.EnableEvents = True
End Sub
 
Upvote 0
I got confused. The Range Name Dave2 doesn't apply to this Workbook Event even though it exists in the macro. That probably changes your resposne. Sorry about that.

Ken
 
Upvote 0
SOLVED!!!!

The following Workbook Event works perfectly:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("Dave1")) Is Nothing Then
FillComments
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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