We can use VBA to Clear only the Comments of a specific range, cells or entire worksheet. we can use ClearComments method of Range Object. Rang.ClearComments method will clear only the comments in a range. And the data, formats like border, font styles, background cell will remain same and will not be disturbed.
50+ Project Management Templates Pack
Excel PowerPoint Word
Advanced Project Plan & Portfolio Template
Ultimate Project Management Template
20+ Excel Project Management Pack
20+ PowerPoint Project Management Pack
10+ MS Word Project Management Pack
Excel VBA to ClearComments a Range – Syntax
Here is the syntax to clear the comments in a range. You can clear the comments in any range or cells using VBA Range.ClearComments method.
Excel VBA to ClearComments in a Range – Examples
The below macro will show you how to clear the comments in a range using VBA. In this example, we are clearing the comments in range “A2 to D10” using VBA.
Sub VBA_Clear_Comments_Range() Range("A2:D10").ClearComments End Sub
Excel VBA to Clear Comments in a Range – Instructions
Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:
- Open an Excel Workbook from your start menu or type Excel in your run command
- Enter some data in any cells in range “A10 to D10” to test this macro. Also format some cell and insert some comments for testing purpose.
- Press Alt+F11 to Open VBA Editor or you can go to Developer Table from Excel Ribbon and click on the Visual Basic Command to launch the VBA Editor
- Insert a Module from Insert Menu of VBA
- Copy the above code (for clearing the comments in a range using VBA) and Paste in the code window(VBA Editor)
- Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
- Press ‘F5′ to run it or Keep Pressing ‘F8′ to debug the code line by line.
Now you can observe that the comments in the range “A2 to D10” are cleared. You can apply any formats and background color, and try this macro. This will clear only the comments. And formats and the data will be remained same.
If you want to clear everything including formats and data, you can use Range.Clear method, to clear the data in a range you use the Range.ClearContents method.
Range.ClearComments: Will clear only the comments. And the data and formats of the range will remain then same.
Range.ClearContents: Will clear only the content/data of the range, formats will remain same.
Range.Clear: Will clear the data including cell formats.
|Excel VBA Reference||Project Management Reference|