VBA – Add or Remove Cell Comments

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on January 10, 2022

This tutorial will demonstrate how to work with Cell comments in VBA.

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

Sheet1.Range("A1").Comment.Delete

Edit Cell Comment Using VBA

3. To edit a comment in a certain cell you need to read the existing comment 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").Comment.Delete
    
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!

 

vba-free-addin

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!)

Free Download

Return to VBA Code Examples