Hi,
I am writing a macro that will delete all comments (on the worksheet) that are empty.
By "Empty" , I mean either of 2 things:
(1) The comment box is absolutely empty: nothing in it.
The user can create such a comment by selecting a cell and clicking a macro button.
The macro creates a comment without User Name.
I created the macro to save space because there may be many comments on the sheet.
(2) But if the user creates a comment using Excel's menu (Insert Comment), and forgets typing anything else, I also
consider it to be an empty comment.
The comment will contain (in bold), say MYCOMPANY:
But if the comment contains something else, say MYCOMPANY: abcdefgh, it is not empty.I tried the code below, but it deletes only those comments that are completely empty.
It does not delete those comments that contain ONLY the User Name.
It does not work even if I hard-code the User Name.
How can we modify the Sub to make it do what I want?
Thanks
Leon
I am writing a macro that will delete all comments (on the worksheet) that are empty.
By "Empty" , I mean either of 2 things:
(1) The comment box is absolutely empty: nothing in it.
The user can create such a comment by selecting a cell and clicking a macro button.
The macro creates a comment without User Name.
I created the macro to save space because there may be many comments on the sheet.
(2) But if the user creates a comment using Excel's menu (Insert Comment), and forgets typing anything else, I also
consider it to be an empty comment.
The comment will contain (in bold), say MYCOMPANY:
But if the comment contains something else, say MYCOMPANY: abcdefgh, it is not empty.I tried the code below, but it deletes only those comments that are completely empty.
It does not delete those comments that contain ONLY the User Name.
It does not work even if I hard-code the User Name.
Code:
Sub DeleteEmptyComments()
Dim C As Comment
Dim User As String
User = Application.UserName & ":"
For Each C In Worksheets("Sheet1").Comments
If C.Text = User Or C.Text = "" Then C.Delete
Next
End Sub
How can we modify the Sub to make it do what I want?
Thanks
Leon