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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,217,101
Messages
6,134,600
Members
449,878
Latest member
Paris Dave

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