ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to add comment into cells by VBA code? (https://www.excelbanter.com/excel-programming/347308-how-add-comment-into-cells-vba-code.html)

Terry

How to add comment into cells by VBA code?
 
Hi,I want to add comment into cells by VBA code. Would you tell me how to
implement? Thanks!



Greg Wilson

How to add comment into cells by VBA code?
 
Try:
Range("A1").AddComment Text:="Monkeys eat banannas"

Regards,
Greg

"Terry" wrote:

Hi,I want to add comment into cells by VBA code. Would you tell me how to
implement? Thanks!




[email protected]

How to add comment into cells by VBA code?
 
Hi

On error resume next
Range("A1").AddComment
on error goto 0
With Range("A1").Comment
.Shape.Placement = xlMoveAndSize
.Shape.Height = 20
.Shape.Width = 30
.Visible = False
.Text "See my example text"
End With

The "on error resume next" and "on error goto 0" are useful if you
don't know if the cell already has a comment. If you know it does not,
then you can omit the error catching. The .Placement is there so that
if you hide columns using code, you won't get an error. If you know you
are not going to hide columns, then you can omit it. The .Visible
property just means you see the tab rather than the whole comment
(until you mouseover). The Height and Width properties can also be
omitted, but hiding and reshowing columns in code can upset the
dimensions of comments.

regards
Paul



All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com