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.
by Allen Wyatt
(last updated August 15, 2015)
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.
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.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
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
Excel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...Discover More
Excel allows you to not only put information into cells, but into comments attached to those cells. Here's how to copy ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.