We can add comments to a range using VBA. When you are automating any task you may wants to write the comments dynamically based on the data. You can use Range.AddComment method to insert a comment to a particular range or a cell. The below example macro codes will show you – how to add or insert comments using VBA in Excel 2003,2007,2010,2013 or higher.
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
Why we need to add comments using VBA
When we are automating any Excel task or preparing the Excel templates, it is better idea to provide enough information to the user. In some cases, the actual Cell or Range may not be sufficient to show the information, or you may want to show the additional information to the user or client (like instructions, help, or about the field, or you may want to to describe more about some data in a range or cell. Adding comments will be a good idea to provide such information, this will also help your worksheet looks more cleaner as comments will not appear until your user or customer hover on the cell or a range.
VBA Add Comments in an Excel Range – Syntax
You can use the below syntax or Macro Code to add or insert comments to a range in Excel using VBA.
Range(“YourRange”).AddCommnet “Your Text”
VBA to Add Comments in an Excel Range – Examples
Please look into the below examples will show adding comments in different situations while automating your tasks.
VBA to Add Comments in an Excel Range – Simple Example
The below example will show you how to add a comment at Range “A2” as ‘Hello, this is a comment text’:
Range("A2").AddComment "Hello, this is a comment text"
Here AddComment is method of an Excel Range to add the comments. And ‘A’ is the Column Name and ‘2’ is the Row number.
VBA to Add Comments in an Excel Range – Instructions
- Open an Excel Workbook from your start menu or type Excel in your run command
- Press Alt+F11 to Open VBA Editor or you can goto 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 adding or inserting c comment into a range 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 a new comment is added at Range A2 as “Hello, this is a comment text”.
Real-time Applications on VBA AddComment to a Range Method
ColorIndex Property of Excel VBA is very useful to set the fill colors, border colors and font colors. Excel VBA ColorIndex returns index values from 1 to 56, -4105 and -4142. You can set the
Very often we need to copy the Excel Range to another sheet with formatting. We can use VBA to automate this task. Excel VBA Copy Range to Another Sheet with Formatting macro is explained to
VBA to filter Multiple Columns code helps applying the filters in multiple columns. Let us see the example macros to filter the records or rows based on items in multiple columns using VBA. Example Data
VBA filter column macro helps filter the data in a specific Column. Let us see different example macros to filter the records or rows based on items in one column. Example Data to Explain the
|Excel VBA Reference||Project Management Reference|