VBA Variable name Problem

The_Captian

New Member
Joined
Nov 18, 2011
Messages
8
Using Excel 2003 SP0

I created a variable called "comment" as a string. Later realized that "Comment" was a method I needed to use, so I changed the variable name to "myComment".
However, now every I try to use ".Comment" the VBA editor changes it to ".comment" and gives an object variable not defined error.

for example, the code:
Sheets("S1").Range(myCell).Comment.Shape.TextFrame.AutoSize = True
is changed to:
Sheets("S1").Range(myCell).comment.Shape.TextFrame.AutoSize = True

and errors.

Is there a way to force a reset of the VBA editor. I have tried closing, re-starting etc. but it refuses to let me use "Comment" as a method.

Thanks in advance for any replies.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Did you delete that line of code saying Dim comment As String?
 
Upvote 0
Yes, I completely removed it. It's like it refuses to acknowledge that it's gone.
(Even used Find to look for it anywhere else)
 
Upvote 0
Yes, I have even re-started the computer.
I may have replaced the variable name "comment" with "myComment" using find/replace. Not sure why that would matter though.

"comment" exists nowhere as a variable in my code, but the editor still continues to auto-correct the ".Comment" method to ".comment" as if it did.
 
Upvote 0
The code is not within a module. It is within the sheet (the workbook has multiple sheets with buttons for running code in each sheet). The naming issue is happening everywhere within the project though (every sheet & in the 1 module).

I deleted the module and pasted code back in, but no luck.

Don't really want to delete the sheet as it has many custom named ranges referenced by the code in it.
 
Upvote 0
As to the capitalization, just add and then immediately delete this line:

Code:
Dim Comment

What is myCell? As writtem, it should be a string variable containing the address of a single cell.
 
Upvote 0
You are correct, myCell is a string holding a cell location.

Tried as you suggested. Created line:
Dim Comment as String
Dim comment as String

Tried one, deleted it, then the other, and deleted it.
Still no luck!

Even the simple line below fails:
Range("A1").comment = "Hello"

Although it works fine in any other project. (Note that .AddComment works fine. I need to access the .Comment method though)

I even tried deleting all the code and all worksheets (other than new insrted one) and all modules. Still will not let my use ".Comment" method in new sheet in this project!
 
Upvote 0
That syntax doesn't work for me at all. This does, if the cell already has a comment:

Code:
Range("A1").Comment.Text "Hello"
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,014
Members
449,280
Latest member
Miahr

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