About the Comment property

In this section, I've been discussing the Comment object. If you dig through the Help system, you'll find that a Range object has a property named Comment. If the cell contains a comment, the Comment property returns a Comment object. For example, the following statement refers to the Comment object in cell A1:


If this were the first comment on the sheet, you could refer to the same Comment object as follows:


To display the comment in cell A1 in a message box, use a statement like this:

MsgBox Range("A1").Comment.Text

If cell A1 does not contain a comment, this statement generates an error.

Note The fact that a property can return an object is a very important concept - a difficult one to grasp, perhaps, but critical to mastering VBA.

0 0

Post a comment