VBA to Delete Empty Comments

azsxdc

New Member
Joined
May 29, 2011
Messages
5
Hi,

I am a VBA Newbie. I was wondering whether it is possible to get a Macro to search for empty comments (or comments with specific values) and Delete them?

Thank you.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You were not clear whether you wanted to only delete empty comments on a particular sheet or on every worksheet in the workbook, so I assumed the latter. Give this macro a try...

Code:
Sub DeleteComments()
  Dim C As Comment, WS As Worksheet
  Const TextToFind As String = ""
  For Each WS In Worksheets
    For Each C In WS.Comments
      If UCase(C.Text) = UCase(TextToFind) Then C.Delete
    Next
  Next
End Sub
If you want to delete comments with a particular text instead of empty comments, just put that text between the two quote marks in the statement that begins with the Const keyword.
 
Upvote 0
Thank you for your answer Rick.

Only on sheet has comments. However, the Workbook is big so it is best to limit the search to one sheet.

I have tried tour Macro, putting it in a module but when I click on the Macro button your Macro is not listed.
 
Upvote 0
Only one sheet has comments. However, the Workbook is big so it is best to limit the search to one sheet.
Here is the code to restrict the macro to only one sheet (assumed to be "Sheet1" for the code... change it as appropriate for your actual setup)...

Code:
Sub DeleteComments()
  Dim C As Comment
  Const TextToFind As String = ""
  For Each C In Worksheets("Sheet1").Comments
    If C.Text = TextToFind Then C.Delete
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,234
Members
452,898
Latest member
Capolavoro009

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