Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Finding and Replacing Text in Comments.

Finding and Replacing Text in Comments

Written by Allen Wyatt (last updated November 8, 2023)
This tip applies to Excel 2007, 2010, and 2013


3

Gerry has a workbook containing 22 worksheets. Each worksheet has about 20 comments. Some of the comments make reference to a company division. He would like to do a mass search and replace of the comments to find each reference (for example, "ABC Division") and replace it with something else (for example, "XYZ subsidiary").

There is no way to do this without using a macro. The regular Find and Replace capabilities in Excel don't allow you to find text within comments, but you can use macro commands. The following is a simple macro to do the replacing:

Sub ReplaceComments()
    Dim cmt As Comment
    Dim wks As Worksheet
    Dim sFind As String
    Dim sReplace As String
    Dim sCmt As String

    sFind = "ABC Division"
    sReplace = "XYZ subidiary"

    For Each wks In ActiveWorkbook.Worksheets
        For Each cmt In wks.Comments
            sCmt = cmt.Text
            If InStr(sCmt, sFind) <> 0 Then
                sCmt = Application.WorksheetFunction. _
                  Substitute(sCmt, sFind, sReplace)
                cmt.Text Text:=sCmt
            End If
        Next
    Next
    Set wks = Nothing
    Set cmt = Nothing
End Sub

The key lines here are those that set the sFind and sReplace variables. You should set those to reflect what you are searching for and what you want it replaced with, respectively. The macro steps through each comment in each worksheet of the current workbook and makes the changes anywhere they are located.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11149) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Finding and Replacing Text in Comments.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quickly Inserting Tables that Don't Go From Margin to Margin

Adding a table to your document is easy. Adding one that doesn't extend from margin to margin may seem a bit harder. ...

Discover More

Copying a Worksheet

Need to make a copy of one of your worksheets? Excel provides a few different ways you can accomplish the task.

Discover More

Copying a Single Cell to Multiple Worksheets

If you need to copy a cell from one worksheet to a bunch of other worksheets, the work can quickly get tedious. Make the ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Placing Formula Results in a Comment

Excel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...

Discover More

Anchoring Comment Boxes in Desired Locations

Want your comment boxes to appear someplace other than the right side of a cell? You may be out of luck, and here's why.

Discover More

Counting Comments in a Worksheet

Need to know how many comments are in a worksheet? You can figure out the count manually, or you can apply the handy ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three minus 2?

2021-04-09 10:55:29

Justin

Is there a way to do this for a certain selection instead of the entire sheet?


2018-01-27 10:48:35

Peter Atherton

Bill

Try this, a mashup of Allen's macro.

Option Explicit


Sub ListComments()
Dim cmt As Comment
Dim wks As Worksheet, cmtsList As Worksheet
Dim sCmt As String, i As Integer
Dim c As range, NextRow As Long

With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For Each wks In ActiveWorkbook.Sheets
If wks.Name = "List Comments" Then
wks.Delete
Exit For
End If
Next wks
Set cmtsList = Worksheets.Add
With cmtsList
.Name = "List Comments"
[A1] = "Sheet Name"
[B1] = "Cell Ref"
[C1] = "Comment Text"
[A1:C1].Font.Bold = True
End With

NextRow = 2
For Each wks In ActiveWorkbook.Worksheets
For Each cmt In wks.Comments
sCmt = cmt.Text
Cells(NextRow, 1) = wks.Name
Cells(NextRow, 2) = cmt.Parent.Address
Cells(NextRow, 3) = sCmt
NextRow = NextRow + 1
Next
Next
cmtsList.range("A1:C1").EntireColumn.AutoFit
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
Set wks = Nothing
Set cmt = Nothing
End Sub


2018-01-26 15:02:41

Bill

is there a way to find all comments in a workbook and list them on a new worksheet by worksheet and cell reference?


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.