Understanding Worksheet.comments.count

hoshi

New Member
Joined
Aug 16, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am trying to add a feature that checks a workbook for the existence of comments.

I imagine that the "ActiveSheet.Comments.Count" would give me the count of the number of comments on the worksheet, however it is returning 0 for me.

Am i misunderstanding the usage of this?

Using Office 365
 

Attachments

  • CommentIssue.png
    CommentIssue.png
    124.5 KB · Views: 40

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:

VBA Code:
Sub testCommentCheck()
  MsgBox CommentsExistsWs(ActiveWorkbook.ActiveSheet)
End Sub

Function CommentsExistsWs(ws As Worksheet)
  CommentsExistsWs = ws.Comments.Count
End Function
 
Upvote 0
Try using
VBA Code:
Sub MM1()
Dim rng As Range
On Error Resume Next
Set rng = activesheet.usedrange.SpecialCells(xlCellTypeComments)
If rng Is Nothing Then: MsgBox "No comments Found": Else: MsgBox "Yay !!"
End Sub
 
Upvote 0
Try using
VBA Code:
Sub MM1()
Dim rng As Range
On Error Resume Next
Set rng = activesheet.usedrange.SpecialCells(xlCellTypeComments)
If rng Is Nothing Then: MsgBox "No comments Found": Else: MsgBox "Yay !!"
End Sub
No such luck.

According to the enumeration docs, that returns cells containing notes. Which i guess arnt comments?

That might be the source of my issues, that in vba land 'Comments' means notes. Does anyone know the reference for comments (as i have in my screenshot?)
 
Upvote 0
I think there may be a misunderstanding here.....Comments in Excel are small "Text Boxes" that appear when a mouse is hovered over a cell or the cell is selected.
The code @DanteAmor and I posted will count the "comments" , which for all intents and purposes are actually "notes inside text boxes"....which are classed as "Comments"
You may need to provide an Example of what you call "comments"
 
Upvote 0
Wow doesn't that get confusing.
For what used to be called comments and are now called Excel Notes used for annotating the spreadsheet, either of these 2 will work:-
VBA Code:
activesheet.cells.SpecialCells(xlCellTypeComments).count
activesheet.comments.count

For threaded comments (new comments with for collaboration).
VBA Code:
activesheet.CommentsThreaded.Count


From Microsoft Documentation:-
The difference between threaded comments and notes

1629173134720.png
 
Upvote 0

Forum statistics

Threads
1,224,938
Messages
6,181,870
Members
453,068
Latest member
DCD1872

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top