Yes. In Excel for Microsoft 365 on Windows, use VBA’s Range.AddComment method to add a note to a cell; Excel still uses “comment” in the method name, but this creates a note, not a modern threaded comment. For example, Worksheets("Sheet1").Range("B2").AddComment "Check this figure." adds a note to cell B2 on Sheet1.
What VBA means by a cell comment
Excel’s terminology can be confusing because the word “comment” has changed meaning over time. In current Excel, a note is a simple annotation attached to a cell, while a comment is a conversation-style thread that can include replies and mentions. The older, note-style feature was called a comment in earlier versions of Excel.
The VBA method Range.AddComment retains that older name. In Microsoft 365, it creates a note. This is useful for a short explanation, a reminder, or background information that should stay with a cell. The note appears when someone points to the cell or opens it, depending on display settings.
A threaded comment is designed for collaboration. It can show replies in a conversation and is associated with Excel’s modern Comments experience. If you specifically need that format, use the threaded-comment method described below, and check that the Excel version running the macro supports it.
Add a note with a simple VBA macro
This example adds a note to B2 on a worksheet named Sheet1. It stops rather than overwriting a note that is already there, so existing information is not silently removed.
Sub AddNoteToCell()
Dim target As Range
' Set the cell that should receive the note.
Set target = ThisWorkbook.Worksheets("Sheet1").Range("B2")
' Avoid replacing a note that may contain useful information.
If Not target.Comment Is Nothing Then
MsgBox "This cell already has a note."
Exit Sub
End If
' Add a note; AddComment is the legacy VBA method name.
target.AddComment Text:="Check this figure before approval."
End Sub
Change Sheet1, B2, and the note text to suit the workbook. The worksheet name must match the tab name exactly. The macro uses ThisWorkbook, meaning the workbook that contains the VBA code. If you instead want the workbook currently active in Excel, VBA has an ActiveWorkbook object, but using it can target the wrong file if several workbooks are open.
To enter the code in Excel for Microsoft 365 on Windows, open the workbook and choose Developer > Visual Basic. In the Visual Basic Editor, choose Insert > Module, paste the code into the module, and return to Excel. Run the macro with Alt+F8, select AddNoteToCell, and choose Run. If the Developer tab is missing, enable it through File > Options > Customize Ribbon by checking Developer.
Target the selected cell or build the text dynamically
If the macro should add a note to whichever cell is selected, use ActiveCell instead of a fixed address. This is convenient for a one-off action, but it makes the result depend on the user’s selection when the macro runs. Make sure the intended cell is selected first.
Sub AddNoteToActiveCell()
Dim target As Range
' Use the currently selected cell on the active sheet.
Set target = ActiveCell
If Not target.Comment Is Nothing Then
MsgBox "This cell already has a note."
Exit Sub
End If
target.AddComment Text:="Review this entry."
End Sub
A note can also be assembled from worksheet values. For instance, a macro could add a reminder containing the value in a neighboring cell. This sample checks for an existing note before adding one and uses the value in A2 as part of the text.
Sub AddNoteUsingCellValue()
Dim ws As Worksheet
Dim target As Range
Dim noteText As String
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set target = ws.Range("B2")
If Not target.Comment Is Nothing Then
MsgBox "This cell already has a note."
Exit Sub
End If
noteText = "Check the entry for: " & CStr(ws.Range("A2").Value)
target.AddComment Text:=noteText
End Sub
Here, the target is B2 and the source value is A2 on Sheet1. If A2 contains “North region,” the note text becomes “Check the entry for: North region.” When working with formulas, remember that Value returns the cell’s calculated value, not necessarily the formula text.
Edit, remove, and display a note
To change an existing note, use the cell’s Comment object. The method name again reflects the older terminology. This example changes the text only if a note exists:
Sub UpdateNoteInCell()
Dim target As Range
Set target = ThisWorkbook.Worksheets("Sheet1").Range("B2")
If target.Comment Is Nothing Then
MsgBox "There is no note to update."
Exit Sub
End If
target.Comment.Text Text:="Updated: verify the source data."
End Sub
To remove a note, use target.Comment.Delete, after first checking that the note exists. Deletion is permanent unless you close the workbook without saving or recover an earlier version. Avoid a macro that deletes notes across a range unless you have deliberately reviewed what it will remove.
Excel normally does not leave every note expanded on screen. You can show one while working by selecting the cell and using the Notes controls on the Review tab, or by right-clicking the cell and choosing the relevant note command. The exact wording can vary slightly between builds. VBA can also set a note’s visibility with target.Comment.Visible = True; set it to False to hide it again. Showing a note is different from adding one.
Use a threaded comment when replies matter
If the goal is a discussion with replies, a note may be the wrong choice. Recent Microsoft 365 desktop versions provide the VBA method Range.AddCommentThreaded for adding a threaded comment. For example, in an environment that supports this method, the key line is target.AddCommentThreaded "Can you confirm this value?". A complete macro would first set target to the desired cell, just as in the note examples.
Threaded-comment support depends on the Excel version and installed object model. A macro that uses this newer method may not run in older Excel releases, so test it in the version where the workbook will be used. If VBA reports that the method or member is unavailable, use a note with AddComment for compatibility, or add the threaded comment through Excel’s interface instead. Do not assume that changing the method name on an existing note macro automatically preserves all the same behavior.
In the Excel interface, select the cell and use Review > New Comment for a conversation-style comment. Review > New Note adds the simpler note. This distinction is helpful when the workbook will be shared: readers can tell whether an annotation is background information or an active discussion.
Common problems and practical checks
- Run-time error when adding a note: The target cell may already have one. Check
target.Commentbefore callingAddComment, then decide whether the macro should stop, update the note, or replace it. - Subscript out of range: A worksheet name in the code may not match the workbook tab. Confirm spelling and spaces, and check that the sheet belongs to the workbook referenced by
ThisWorkbook. - The note appears on the wrong sheet: Code using
ActiveSheetorActiveCelldepends on what is active at run time. Qualify the worksheet and range explicitly when the destination must always be the same. - The macro cannot be found or run: Put the procedure in a standard module and make sure macros are permitted by the organization’s security settings. Do not enable macros in a file from an untrusted source merely to view its contents.
- The text is difficult to read: Keep notes concise. If a note needs lengthy explanations, a separate documentation sheet or a threaded conversation may be clearer than a large cell annotation.
One common misconception is that AddComment creates the same kind of item as Review > New Comment in current Excel. It does not: the VBA method creates a note. Another is that a cell can hold several independent notes. A cell has one note of this type; adding another requires handling the existing note first.
Save the workbook and run macros safely
A workbook containing VBA should generally be saved as an Excel Macro-Enabled Workbook (.xlsm). If you save VBA code in a standard .xlsx file, Excel cannot retain the macro in that format. Use File > Save As and select the macro-enabled workbook type when you need the code to remain with the file.
Save a copy of the workbook before running a macro that changes cells or annotations. VBA actions cannot be undone with Ctrl+Z, so a macro that adds, edits, or deletes notes may not be recoverable through Excel’s normal Undo command. Test changes on a copy first, particularly if the procedure loops through many cells or replaces existing notes.
On Mac, Excel also includes the Visual Basic Editor and supports VBA, though keyboard shortcuts and some interface details differ from Windows. Use the Developer tab or the Mac Visual Basic Editor command to open the editor; shortcuts can vary with the keyboard layout and macOS settings. The Excel object model examples above are intended for desktop Excel, not Excel for the web, which cannot run VBA macros.
When to use VBA and when to use Excel’s interface
VBA is useful when the same annotation must be added repeatedly, when a macro fills notes based on worksheet data, or when a larger workflow already uses VBA. It can standardize wording and reduce manual steps, but it also introduces code that must be maintained and allowed to run.
For a single cell, the interface is usually simpler: select the cell, then choose Review > New Note or Review > New Comment according to the kind of annotation needed. For many cells, consider whether a dedicated column such as “Review status” or “Explanation” would make the information easier to filter, search, and export. Notes are attached to cells, but they are not a substitute for structured data when the information needs to be analyzed.
Frequently Asked Questions
What VBA code adds a comment to a cell?
Use Range.AddComment, such as Worksheets("Sheet1").Range("B2").AddComment "Check this figure.". In current Excel this adds a note, despite the method’s older name.
How do I add a note to the active cell?
Set a range variable to ActiveCell, check whether its Comment property is Nothing, and then call AddComment. This targets the selected cell on the active sheet.
Does AddComment create a threaded comment?
No. Range.AddComment creates a note. Recent Microsoft 365 desktop Excel versions can use Range.AddCommentThreaded for a threaded comment, but older versions may not support that method.
How can I replace an existing note?
Check whether the cell already has a note, then either update its text with target.Comment.Text or delete it before adding a replacement. Decide explicitly which behavior is appropriate so useful text is not removed by accident.
Can VBA macros run in Excel for the web?
No. Excel for the web does not run VBA macros. Open the macro-enabled workbook in desktop Excel to run VBA; the web version can still be used for many workbook tasks that do not require running the macro.
Related
- Split a Cell in Excel: Separate Text or Unmerge Cells
- How to Merge Cells in Jupyter Notebook: A Practical Guide
- Draw.io Table Merge Cells: Steps and Common Problems
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Loop Through a PivotTable: Examples and TipsTo loop through a PivotTable in Excel VBA, assign it to a PivotTable variable and use a For…
- Excel VBA VLOOKUP: Examples, Errors, and AlternativesIn Excel VBA, use Application.VLookup(lookup_value, table_array, column_index, False) to find an exact match in the first column of…
- VBA Copy and Paste Special: Examples and OptionsIn Excel VBA, copy a range and paste only selected content with Range.Copy followed by Range.PasteSpecial. For example,…
- Excel VBA vs Power Query: Key Differences and When to Use EachUse Power Query when the main job is importing, cleaning, combining, and reshaping data that you will refresh;…
- Excel Macro Message Box: How to Create and Use OneAn Excel macro message box is a pop-up created with VBA’s MsgBox function. In Excel for Microsoft 365…
- VBA Copy and Paste a File: Practical Code and Safe StepsTo copy a file with VBA in Excel for Microsoft 365 on Windows, use the FileCopy statement or…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.