You can modify a cell comment in Excel with VBA by setting the Text property of the Comment object, for example Range("A1").Comment.Text "New note". If the cell has no comment yet, create one first with AddComment, then change its text. The same pattern lets you edit, append, hide, resize or delete comments across many cells at once, which is far faster than right-clicking each one.
What You'll Need
- Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > check Developer; on Mac, Excel > Preferences > Ribbon & Toolbar).
- A workbook saved as .xlsm (macro-enabled) if you want the code to persist.
- Basic familiarity with the VBA Editor (Alt+F11 on Windows, Option+F11 on Mac).
- Macro security set to allow macros in trusted locations; otherwise the code will not run.
Step-by-Step
- Open the VBA Editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project Explorer, right-click your workbook and choose Insert > Module. Menu labels can differ slightly by version and region.
- Write a simple edit macro. Paste this into the module:
This checks whether a comment exists before changing it, which prevents the common "Object variable not set" error.Sub EditComment() Dim c As Comment Set c = Range("A1").Comment If c Is Nothing Then Range("A1").AddComment "Updated note" Else c.Text "Updated note" End If End Sub - Run the macro. Place the cursor inside the subroutine and press F5, or go back to Excel and use Developer > Macros, select EditComment, and click Run.
- Append text instead of replacing it. To keep the original note and add to it, use:
This prepends a label while preserving the existing content.With Range("A1").Comment .Text "Reviewed: " & .Text End With - Loop through many cells. To update every comment on a sheet:
This touches only cells that already have comments, so no error occurs on blank cells.Sub UpdateAllComments() Dim c As Comment For Each c In ActiveSheet.Comments c.Text "Reviewed - " & c.Text Next c End Sub - Change visibility and size. Use
c.Visible = Falseto hide the comment indicator orTrueto show it. Setc.Shape.Widthandc.Shape.Heightto resize the comment box. - Delete comments when needed.
Range("A1").ClearCommentsremoves the comment from one cell;ActiveSheet.Cells.ClearCommentsremoves all comments on the sheet. This cannot be undone with Ctrl+Z after the macro runs, so save a copy first. - Save the workbook as .xlsm. Use File > Save As and choose Excel Macro-Enabled Workbook. A standard .xlsx save strips the macro.
Common Mistakes
- Calling
.Comment.Texton a cell with no comment. Always testIf c Is Nothingfirst. - Using
AddCommenton a cell that already has one, which raises an error. Check for an existing comment before adding. - Forgetting that
Comment.Textreplaces the entire note; use concatenation to append. - Saving as .xlsx and losing the macro. Use .xlsm.
- Assuming comments and notes are the same. In newer Excel versions, threaded comments use a different object model and are not edited by the
Commentobject; legacy notes are.
Tips
- Record a macro while manually editing a comment to capture the exact syntax your version generates.
- Use
On Error Resume Nextsparingly; it hides real problems. Prefer explicit checks. - Store the target range in a variable so you can reuse the code on different sheets.
- Test on a copy of the workbook before running loops that delete or overwrite comments.
- Comment text has a length limit; very long notes may be truncated.
Troubleshooting
- Macro does nothing: check macro security settings and confirm the code is in a standard module, not a sheet module.
- "Object variable or With block variable not set": the cell has no comment. Add the
Is Nothingcheck. - "Application-defined or object-defined error": often means you tried to add a comment where one exists, or the sheet is protected. Unprotect the sheet first.
- Comments disappear after saving: you saved as .xlsx. Re-save as .xlsm.
- Threaded comments not changing: the code targets legacy notes. Edit threaded comments manually or via the newer comment APIs if your version supports them.
Frequently Asked Questions
Can I edit a comment without deleting the old text?
Yes. Read .Comment.Text and concatenate the new text, then assign it back.
Does this work on Excel for Mac?
Yes, the VBA object model for comments is the same, though shortcut keys differ (Option+F11).
Can I change the comment author?
The author is set when the comment is created and is not directly editable through the Comment object in all versions; recreating the comment is the reliable route.
Will macros edit threaded comments?
Legacy notes are handled by the Comment object. Threaded comments use a different model and may not be editable with the same code.
How do I remove all comments at once?
Use ActiveSheet.Cells.ClearComments, after saving a backup because it cannot be undone.