1

I had the same Problem as in this post. The answer that was given, did what was asked, it executed code when a given cell is changed.

It also worked for me, except when I try to change the name of the Sub to anything else, the code stops being executed. No warning is given. Does anyone know why that is?

This is the code that was the solution to the previous question:

Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Me.Range("D2")) Is Nothing Then Exit Sub Application.EnableEvents = False 'to prevent endless loop MsgBox "You changed THE CELL!" Application.EnableEvents = True End Sub 

or as a shorter Version

Private Sub Worksheet_Change(ByVal Target As Range) IF Target.Address = "$D$2" Then MsgBox("Cell D2 Has Changed.") End If End Sub 

Both Subs react the same way when I change their name. Is there a trigger somewhere that calls the macro, where I would have to also change the name?

1
  • 2
    The code stub Private Sub Worksheet_Change(ByVal Target As Range) is the event code that fires when the Worksheet object is changed. If you change the name, then the code won't automatically fire when worksheet is changed. Commented Jul 24, 2015 at 13:09

2 Answers 2

2
Private Sub Worksheet_Change(ByVal Target As Range) 

Is an event. It is called up by the system and HAS to be named like that

Here is a bit of reading for you to learn more

http://www.cpearson.com/excel/Events.aspx

Sign up to request clarification or add additional context in comments.

Comments

2

You cannot change the name of a method for worksheet events.

This name is how the VBA knows that this method should be fired when something is changed in worksheet.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.