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

Finding and Replacing Text in Comments

Written by Allen Wyatt (last updated March 14, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


1

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 (3534) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Checking Up On Numbers

When do you use digits in your prose and when do you spell out the numbers? Why not let Word help you make the decision? ...

Discover More

Selecting Visible Cells in a Macro

Many times you need to select just the visible cells before taking some action. It is helpful to know how to make this ...

Discover More

Entering or Importing Times without Colons

Enter a time into a cell and you normally include a colon between the hours and minutes. If you want to skip that pesky ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Editing a Comment Close to Its Cell

Have you ever chosen to edit a comment, only to find that the comment is quite a ways from the cell with which it is ...

Discover More

Inserting Workbook Comments Into a Cell

One of the pieces of information that Excel can maintain relative to a workbook is a set of comments of your choice. ...

Discover More

Changing the Comment Color

Normally Excel displays comments in a color reminiscent of sticky notes you keep around your office. If you want them to ...

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 5 - 3?

2022-03-27 19:51:18

Jen

This is great, thanks Allen!

Just wondering if it is possible to include wildcards in the 'find' part of the macro?
Eg. I've saved a Google Sheets doc as .xlsx and all the comments that transposed over now starts with 3 lines of junk (see below). I'd like to automatically remove these 3 lines from comments that have them. (However there are comments added since that don't so I can't just delete first 3 lines of all comments.) So if this was Find/Replace in Word, could use wildcards to:
1. replace the "===" AND the line break (^p or ^l) that follows it
2. use the equivalent of * wildcard to search for everything that starts with "ID" and finishes with a line break, and similarly replace "Jenni Downes" and the date content inside parentheses ( ).

Is there a way to do this via your macro? (Or any other way?)


Google Sheets comments start with 3 lines that look like this:

===========
ID#AAAAUtGJikI
Jenni Downes (2022-02-14 21:30:05)
...actual comment starts here on 4th line...


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.