Reputation: 53
As I click on the particular cells in excel, comments appears that disturb me much so I want vba code to delete all the comments instantly in the active worksheet.
Upvotes: 2
Views: 14998
Reputation: 1
Please see my reply
Sub delete_comments()
Dim i As Range
For Each i In ActiveSheet.UsedRange
i.ClearNotes
Next i
End Sub
Upvotes: -3
Reputation: 13292
All you really need to do is get a range, then clear comments:
Worksheets("MySheet").Activate
ActiveSheet.UsedRange.ClearComments
Does that help?
More Detail To get the above code to work, there are several approaches. The one I recommend here is:
When back in Excel, hit to bring up the Run Macro window. You should see your RemoveComments macro listed. Now click Run and your comments should be removed.
I actually tested this, so it will work if done properly. If it still doesn't work for you, be sure that the worksheet in question is the first worksheet in your workbook. If it isn't, then change Worksheets(1).Activate in your RemoveComments Sub so that it refers to the correct worksheet.
Sub RemoveComments()
Worksheets(1).Activate
ActiveSheet.UsedRange.ClearComments
End Sub
Upvotes: 6