Today we learn interesting new VBA code using comments in our Excel worksheet. Our data contains name of students and their marks in Math. Of course, we could also use sales or financial data. Now we have placed comments for students who need to improve their skills in Math to achieve greater scores. Let’s see how we can count the total number of comments, change the shape of the comments, display or hide the comments automatically on our Excel worksheet using VBA.
We write the following sub-routines or macros in our module. The names of the macros are self-explanatory.
Dim TotalComments As Integer
TotalComments = ActiveSheet.Comments.Count
MsgBox “The active worksheet has ” & TotalComments & ” comments.”, vbInformation
Dim cmnt As Comment
For Each cmnt In ActiveSheet.Comments
If cmnt.Shape.AutoShapeType = msoShapeRectangle Then
cmnt.Shape.AutoShapeType = msoShapeRoundedRectangle
cmnt.Shape.AutoShapeType = msoShapeRectangle
If Application.DisplayCommentIndicator = xlCommentAndIndicator Then
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
Application.DisplayCommentIndicator = xlCommentAndIndicator
Watch the Excel training video to understand the functioning of the VBA code quickly and easily:
You can watch this video on YouTube.