VBA – Add or Remove Cell Comments

Modifying a worksheet from code? Add a cell comment to let the user know about what you’ve just done! The following code snippets show you how to add or delete a comment in a cell.

Add Cell Comment Using VBA

1. Put the following code somewhere in your macro to add a comment

Sheet1.Range("A1").AddComment ("Hello World")

Delete Cell Comment Using VBA

2. To delete a comment use this code

AutoMacro - VBA Code Generator

Edit Cell Comment Using VBA

3. To edit a comment you need to read the existing one and edit it. Use the code below

Dim OldComment As Variant
Dim NewComment As Variant

OldComment = Sheet1.Range("A1").Comment.Text
NewComment = OldComment & " Edited comment"
Sheet1.Range("A1").AddComment (NewComment)

First, you need to read the existing comment in OldComment variable.

After that you can edit a comment, e.g. add the new text to the existing one in NewComment variable.

Now, you need to delete the old comment and add the new one. In order to delete the comment, you have to use the .Comment.Delete command.

Finally, you can add the comment from the NewComment variable using the .AddComent command.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text


Learn More!

<<Return to VBA Examples

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)