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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try

Code:
If Intersect(Target, Range("Text")) Is Nothing Then Exit Sub
 
Upvote 0
Try

Code:
If Intersect(Target, Range("Text")) Is Nothing Then Exit Sub

I made the change :
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

But it didn't work.

Ken
 
Upvote 0
It works for me. Where did you put the code? You have to right click the sheet tab, select View Code and paste in the code.

The FillComments sub should go in a regular module.
 
Upvote 0
My macro code FillComments is in Module 1 and the code you provided is in Sheet 5.

I now get a Compile Error - "Text" Invalid Outside Procedure.
 
Upvote 0
Make sure that Sheet5's code is just

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

without any extraneous statements outside that procedure.
 
Upvote 0
Make sure that Sheet5's code is just

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

without any extraneous statements outside that procedure.

Yes it is exactly that.

I've just noticed that the compile error refers to my macro:

Application.Goto Reference:="Text"
Dim Cell As Range
Selection.ClearComments
For Each Cell In Selection
Cell.AddComment Cell.Text
Cell.Comment.Visible = False
Cell.Comment.Shape.TextFrame.AutoSize = True
Next Cell


Dim C As Comment, WS As Worksheet
Const TextToFind As String = ""
For Each WS In Worksheets
For Each C In WS.Comments
If UCase(C.Text) = UCase(TextToFind) Then C.Delete
Next

Next
Application.Goto Reference:="Text"
Selection.Copy
Application.Goto Reference:="Import"
Selection.PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.Goto Reference:="Text"
Application.CutCopyMode = False
Selection.ClearComments
Range("K28").Select
End Sub
 
Upvote 0
You would need to code like this

Application.Goto Reference:=Range("Text")

wherever you use Application.GoTo
 
Upvote 0
I made the change to all the GoTo instructions but I still get eraxactly he same error.

I really appreciate your patience.

Cheers,
Ken
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,225
Members
448,877
Latest member
gb24

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