Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse VBA code to add and remove comments in Excel cells
DescriptionThis example shows how to use VBA code to add and remove comments in Excel cells
KeywordsVBA, Excel, comment, remark
CategoriesOffice
 
To make a comment, use a Cell's Comment object. First if the Cell does not have a Comment object, usethe Cells AddComment method to create one. Then use the Comment object's Text method to assign text to it.
 
' Add a comment.
Private Sub cmdMakeComment_Click()
Dim rng As Range

    Set rng = ActiveSheet.Cells(4, 4)
    If rng.Comment Is Nothing Then rng.AddComment
    rng.Comment.Text "It is now " & Format(Now)
End Sub
 
To remove a comment, call the Comment object's Delete method.
 
' Remove a comment.
Private Sub cmdRemoveComment_Click()
Dim rng As Range

    Set rng = ActiveSheet.Cells(4, 4)
    If Not (rng.Comment Is Nothing) Then rng.Comment.Delete
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated