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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I have changed the ranges to different names but it still reports a compile error in the first line. I then replaced the range name with cell references - same error.

Very confusing......

Ken
 
Upvote 0
Please can you post all of the code that you have in Module 1 - please use code tags

[code]
code goes here
[/code]
 
Upvote 0
Please can you post all of the code that you have in Module 1 - please use code tags

[code]
Application.Goto Reference:=Range("Dave1")


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:=Range("Dave1")


Selection.Copy
Application.Goto Reference:=Range("Dave2")
Selection.PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.Goto Reference:=Range("Dave1")


Application.CutCopyMode = False
Selection.ClearComments
Range("K28").Select
End Sub
[/code]

This code is actually in Module 4

Ken
 
Upvote 0
You are missing the Sub declaration

Rich (BB code):
Sub FillComments()
Application.Goto Reference:=Range("Dave1")


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:=Range("Dave1")


Selection.Copy
Application.Goto Reference:=Range("Dave2")
Selection.PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.Goto Reference:=Range("Dave1")


Application.CutCopyMode = False
Selection.ClearComments
Range("K28").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,604
Messages
6,125,792
Members
449,260
Latest member
Mrw1

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