This guide shows you how to create, read, and manage notes (also called cell comments) in Excel using VBA. With a few lines of code, you can add a note to a cell, retrieve its text, update it, or delete it—all without touching the mouse. You’ll need a workbook with some data and the Visual Basic Editor (VBE), which is built into Excel.
What You’ll Need
- Microsoft Excel (2016, 2019, 2021, or Microsoft 365) on Windows. Steps are similar on Mac, but the VBE shortcut differs.
- A workbook with at least one worksheet containing data. For the examples, we’ll use cells A1 and B1.
- Basic familiarity with the VBA editor (opening it, inserting a module).
Step-by-Step
- Open the Visual Basic Editor. Press
Alt + F11on Windows (on Mac,Fn + Option + F11). If you’re in Excel for the web, VBA is not supported—use the desktop version. - Insert a module. In the VBE, go to Insert > Module. This creates a blank code window where you’ll write your macros.
- Write a macro to add a note. Type the following code into the module. This adds a note to cell A1 on the active sheet.
Sub AddNote() ' Adds a note to cell A1 Dim ws As Worksheet Set ws = ActiveSheet ' Remove any existing note first ws.Range("A1").ClearNotes ' Add the note with text ws.Range("A1").AddComment "This is a note." End SubRun it by pressing
F5while the cursor is inside the macro. You’ll see a red triangle on A1; hover to see the note. - Read a note’s text. To retrieve the text from a note, use the
Commentproperty. This macro displays the note in a message box.Sub ReadNote() Dim ws As Worksheet Set ws = ActiveSheet Dim noteText As String If ws.Range("A1").Comment Is Nothing Then noteText = "No note exists." Else noteText = ws.Range("A1").Comment.Text End If MsgBox noteText End Sub - Edit an existing note. The
Comment.Textproperty can be set. This macro changes the note on A1 to a new text.Sub EditNote() Dim ws As Worksheet Set ws = ActiveSheet ' Check if note exists If ws.Range("A1").Comment Is Nothing Then MsgBox "No note to edit. Add one first." Else ws.Range("A1").Comment.Text "Updated note text." End If End SubNote: When setting
.Text, you must pass the new text as an argument, not assign it directly. - Delete a note. Use
ClearNotesto remove all notes from a range, orDeleteon the comment object.Sub DeleteNote() Dim ws As Worksheet Set ws = ActiveSheet ' Deletes only the note on A1 If Not ws.Range("A1").Comment Is Nothing Then ws.Range("A1").Comment.Delete End If End Sub - Loop through all notes on a sheet. This macro lists every cell that has a note and its text.
Sub ListAllNotes() Dim ws As Worksheet Set ws = ActiveSheet Dim cmt As Comment Dim output As String For Each cmt In ws.Comments output = output & cmt.Parent.Address & ": " & cmt.Text & vbNewLine Next cmt If output = "" Then MsgBox "No notes found." Else MsgBox output End If End SubHere,
cmt.Parentreturns the range that the comment is attached to. - Add a note with author name. The
AddCommentmethod uses the current Windows username. To set a custom author, you can modify theAuthorproperty after adding.Sub AddNoteWithAuthor() Dim ws As Worksheet Set ws = ActiveSheet ws.Range("B1").ClearNotes ws.Range("B1").AddComment "Review this." ws.Range("B1").Comment.Author = "Analyst" End Sub
Common Mistakes
- Forgetting to clear existing notes before adding. If a cell already has a note,
AddCommentwill raise an error. Always useClearNotesor check ifComment Is Nothing. - Using
.Textincorrectly. To set text, you must callComment.Text "new text"—not assign likeComment.Text = "new text". The latter causes a compile error. - Assuming notes are the same as threaded comments. In Excel 365, there are two types: legacy notes (this article) and threaded comments (introduced later). VBA’s
Commentobject works only with legacy notes. Threaded comments require a different object model (not covered here). - Running macros without saving a backup. VBA actions cannot be undone with Ctrl+Z. Always save a copy of your workbook before running any macro that modifies data or notes.
Tips
- Use
ClearNoteson a whole range to remove multiple notes at once. For example,ws.Range("A1:C10").ClearNotes. - Check for existing notes with
If Not rng.Comment Is Nothing. This avoids errors and is faster than relying on error handling. - To add a note to a cell with a formula, the note is independent of the formula. You can add notes to any cell, even if it contains a value or formula.
- Notes are stored with the workbook. When you share the file, others can see the notes. If you want to hide them, use
Application.DisplayCommentIndicator = xlNoIndicator(or set the sheet’sDisplayCommentsproperty). - Use the
Comment.Shapeproperty to adjust the note’s size or position. For example,rng.Comment.Shape.Width = 200sets the width in points.
Troubleshooting
- “Run-time error 1004: Application-defined or object-defined error” when adding a note: The cell already has a note. Use
ClearNotesfirst, or check withIf rng.Comment Is Nothing. - “Compile error: Method or data member not found” when using
.Text: Ensure you’re using the correct syntax. For setting text, useComment.Text "..."(not=). For reading,Comment.Textworks fine. - Notes not visible even after adding. Check if comments are hidden in the workbook. Go to File > Options > Advanced and under Display, select “Indicator and comments on hover” or “Comment indicator only”.
- Macro works in one sheet but not another. Ensure the sheet is active or explicitly reference the sheet by name, e.g.,
ThisWorkbook.Worksheets("Sheet1")instead ofActiveSheet. - When using
For Each cmt In ws.Comments, it doesn’t find any comments. Make sure the comments are legacy notes, not threaded comments. Threaded comments are not part of theCommentscollection.
Frequently Asked Questions
- Can I add a note to a cell without using VBA? Yes, you can manually right-click a cell and choose “New Note” (or “Insert Comment” in older versions). VBA automates this for many cells at once.
- What’s the difference between a note and a comment in Excel? In Excel 365, “notes” are the legacy yellow sticky notes, while “comments” are threaded discussions. VBA’s
Commentobject refers to notes. Threaded comments are accessed differently. - Can I make a note automatically appear when a cell changes? Yes, you can use the
Worksheet_Changeevent to add a note when a cell’s value changes. For example, add a note with the timestamp. - How do I remove all notes from an entire workbook? Loop through all worksheets and use
Cells.ClearNoteson each sheet. Example:For Each ws In ThisWorkbook.Worksheets: ws.Cells.ClearNotes: Next ws. - Can I export notes to a separate text file? Yes, you can loop through the
Commentscollection and write the cell address and text to a text file usingOpenandPrint #statements. - Why does my note show the wrong author? The author is taken from your Windows username by default. To change it, set the
Comment.Authorproperty after adding the note.
Related
- C Battery Diameter: Exact Size and What It Means
- Data Entry Software for Smart Grids: A Practical Guide
- Shortcut to Close All Tabs? Quick Keys & Steps
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA AutoFilter: Exclude Multiple ValuesExcel VBA AutoFilter cannot use an array of “not equal to” criteria as a general exclusion list. An…
- VBA Find a Plumber in an Excel Contact ListTo find plumber listings in an Excel contact list with VBA, search the column that contains service categories…
- VBA AutoFilter Not Working? Common FixesIf VBA AutoFilter is not working, first check that the macro targets the correct worksheet and a contiguous…
- Excel VBA Copy and Paste Formatting Without Changing ValuesTo copy formatting with Excel VBA without copying cell values or formulas, copy the source range and paste…
- Excel Macro Location: Where VBA Code Is StoredIn Excel for Microsoft 365 on Windows, a macro is usually stored as VBA code inside the workbook…
- Excel VBA Math Functions: What They Do and How to Use ThemExcel VBA includes built-in math functions such as Abs, Sqr, Log, Sin, and Round, which you can call…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.