To insert a note in Excel using VBA, use the AddComment method on a Range object (legacy comments are called notes in modern Excel). For example, Range("A1").AddComment "Your note text" adds a note to cell A1. For threaded comments, use AddThreadedComment (Excel 365 only). This guide walks you through both methods, plus common pitfalls and fixes.

What You'll Need

  • Microsoft Excel (any recent version; threaded comments require Excel 365 or Excel 2021+).
  • Basic familiarity with the VBA editor (how to open it and run a macro).
  • Macro-enabled workbook (.xlsm) if you want to save your code.

Step-by-Step

  1. Open the VBA editor. Press Alt + F11 (Windows) or Fn + Option + F11 (Mac). The Visual Basic for Applications window opens.
  2. Insert a module. In the Project Explorer, right-click your workbook name, choose Insert > Module. A blank code window appears.
  3. Write a simple macro to add a note. Type the following code:
    Sub AddNote()
        Range("A1").AddComment "This is a note"
    End Sub
    This uses the legacy comment system, which Excel now labels as “Notes”. The note will appear with a red triangle in the corner of cell A1.
  4. Run the macro. Press F5 or click the green Run button. Switch back to Excel (Alt+F11 again) to see the note indicator.
  5. Add a threaded comment (Excel 365/2021+). Use AddThreadedComment instead:
    Sub AddThreadedComment()
        Range("B2").AddThreadedComment "Please review this figure"
    End Sub
    Threaded comments support replies and @mentions. Note: this method is not available in older Excel versions.
  6. Check for existing notes before adding. If a cell already has a note, AddComment will fail. Use On Error Resume Next or check Range("A1").Comment Is Nothing first. Example:
    If Range("A1").Comment Is Nothing Then
        Range("A1").AddComment "New note"
    End If
  7. Save your workbook as .xlsm. Go to File > Save As and choose “Excel Macro-Enabled Workbook (*.xlsm)”. Otherwise your macro will be lost on close.

Menu labels and dialog wording can differ slightly by Excel version, platform, and region. The steps above are for Windows desktop Excel; on Mac, the VBA editor is similar but keyboard shortcuts may vary.

Common Mistakes

  • Using AddComment on a cell that already has a note. This throws a “Application-defined or object-defined error”. Always check Comment Is Nothing first or clear the existing note with ClearComments.
  • Confusing notes with threaded comments. AddComment creates a legacy note (red triangle), while AddThreadedComment creates a modern threaded comment. They are not interchangeable.
  • Forgetting to enable macros. If macros are disabled, your code won’t run. Check the Trust Center settings (File > Options > Trust Center > Trust Center Settings > Macro Settings) and enable macros for the session.
  • Saving as .xlsx. Macros are stripped from standard .xlsx files. Save as .xlsm.
  • Referencing a range incorrectly. Use Range("A1") or Cells(1,1), not Range("A1:A5") for a single note. For multiple cells, loop through them.

Tips

  • To add notes to multiple cells at once, loop through a range:
    Dim c As Range
    For Each c In Range("A1:A10")
        If c.Comment Is Nothing Then c.AddComment "Note for " & c.Address
    Next c
  • Use Range("A1").Comment.Text to read or modify an existing note’s text.
  • To delete a note, use Range("A1").ClearComments.
  • For threaded comments, you can add replies with AddReply on the comment object (Excel 365 only).
  • Always test your macro on a copy of your workbook first, especially if it modifies many cells.

Troubleshooting

If your macro does not work as expected, try these steps in order:

  1. Check for error messages. Press Ctrl + Break to stop a running macro, then review the highlighted line. Common errors: “Object required” (range not set), “Application-defined error” (note already exists).
  2. Verify macro security. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and ensure “Disable all macros with notification” or “Enable all macros” is selected (not recommended for untrusted files).
  3. Confirm the cell reference. Use Debug.Print Range("A1").Address to check you are targeting the right cell.
  4. Check Excel version. AddThreadedComment is not available in Excel 2019 or earlier. Use AddComment instead.
  5. Reinstall or repair Office if the VBA editor behaves erratically. This is a last resort; back up your files first.

If the problem persists, search Microsoft’s official documentation for the specific error code, or ask in the Microsoft Answers community.

Frequently Asked Questions

Can I add a note without using VBA?

Yes. Right-click a cell and choose New Note (or Insert Comment in older versions). VBA is only needed for automation.

What is the difference between a note and a comment in Excel?

In modern Excel, “notes” are the legacy comments (red triangle) and “comments” are threaded discussions. VBA’s AddComment creates a note; AddThreadedComment creates a threaded comment.

Why does my macro give a “1004” error?

Error 1004 often means the cell already has a note. Check with If Range("A1").Comment Is Nothing Then before adding.

Can I format the text inside a note?

Yes, but only with legacy notes. Use Range("A1").Comment.Text Text:="Hello", Font:="Arial", Size:=10 to set basic formatting. Threaded comments do not support rich text formatting via VBA.

Do notes work in Excel Online?

Excel Online displays notes but does not support running VBA macros. Use the desktop app for macro execution.

How do I delete all notes in a worksheet?

Use Cells.ClearComments to remove all notes and threaded comments from the active sheet. Be careful: this cannot be undone.