Worksheet Change + Call "Macro"

andrefenti

New Member
Joined
Jun 5, 2018
Messages
4
Hi everyone!

I have a code I am trying to run, but it keeps showing this message:

"Compile Error:

Invalid use of property"

_________________________
This is the code:

Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 12 Then
Sheets("Display TRT").Select
Call Comments
MsgBox "It worked"
End If
End Sub

________________________

"Comments" is a Sub that runs with no problems when I click on na option button.

I want this macro to run whenever I change any cell on the 12th column of the sheet.

When I take off the "Call Comments" line, the problem does not happen.

Does anyone know how I can fix this??


Att.,
André Fenti Yamamoto
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the Board!

"Comments" is also a reserved word in VBA.
The problem with using reserved words, is Excel VBA cannot tell if you are trying to call the Subprocedure "Comments" or the Property/Method "Comments".

You want to avoid using Reserved words as the name of your procedures, functions, objects, and variables for this exact reason.
Change the Procedure name to something like "MyComments" and it will work (tested and verified).
When I code, I add this "My" prefix to any word that I think might possibly be a reserved word, just to be safe.
 
Last edited:
Upvote 0
It worked!!!! Thank you very much!



welcome to the board!

"comments" is also a reserved word in vba.
The problem with using reserved words, is excel vba cannot tell if you are trying to call the subprocedure "comments" or the property/method "comments".

You want to avoid using reserved words as the name of your procedures, functions, objects, and variables for this exact reason.
Change the procedure name to something like "mycomments" and it will work (tested and verified).
When i code, i add this "my" prefix to any word that i think might possibly be a reserved word, just to be safe.
 
Upvote 0
You are welcome!
Glad I was able to help!:)
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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