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 in Text Boxes.

Finding and Replacing in Text Boxes

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


David wonders if it is possible to use Find and Replace to locate and modify text in text boxes or in labels in charts. The short answer is that it is not possible, but there are several workarounds you can try.

First, you could easily make the text in your text boxes or in your chart labels dynamic, so that it is tied to the contents of some worksheet cells. For instance, you could do the following for your text boxes:

  1. Copy your text from each of text boxes to a range of cells on your worksheet. (For this example, assume that you copied the contents of ten text boxes to the range Z1:Z10.)
  2. Select the first text box (the one that corresponds to cell Z1) and get rid of the text box's contents.
  3. With the text box still selected, enter the following into the Formula bar: =Z1. When you press Enter, the text box should reflect whatever is in cell Z1.
  4. Repeat steps 2 and 3 for each of your other text boxes, using the appropriate cell reference for each in step 3.

That's it. You can use the same technique with custom chart labels—all you need to do is select the chart label and enter a cell reference in the Formula bar. With the text boxes and chart labels tied to worksheet cells, you can easily use Find and Replace to search for and change information in the cells. When the changes are made, the text boxes and chart labels should automatically reflect the changes in the cells.

The only way to actually change the text within a text box or chart label is to change it manually or change it using a macro. The code would need to step through each text box in the worksheet and then make your change. The following is a simple version of a macro that can make such a change.

Sub TextBoxReplace()
    Dim shp As Shape
    Dim sOld As String
    Dim sNew As String

    'Change as desired
    sOld = "Old string"
    sNew = "New string"
    On Error Resume Next
    For Each shp In ActiveSheet.Shapes
        With shp.TextFrame.Characters
            .Text = Application.WorksheetFunction.Substitute( _
              .Text, sOld, sNew)
        End With
    Next
End Sub

This macro steps through all the shapes in the worksheet (text boxes are shapes) and then replaces whatever is in the sOld variable with whatever is in the sNew variable. Applying the same technique to chart labels is only a bit more complex, as shown in the following macro:

Sub ChartLabelReplace()
    Dim Cht As ChartObject
    Dim Ser As Series
    Dim scPt As Point
    Dim sOld As String
    Dim sNew As String

    'Change as desired
    sOld = "Old String"
    sNew = "New String"
    On Error Resume Next
    For Each Cht In ActiveSheet.ChartObjects
        For Each Ser In Cht.Chart.SeriesCollection
            For Each scPt In Ser.Points
                With scPt.DataLabel
                    .Text = Application.WorksheetFunction.Substitute( _
                      .Text, sOld, sNew)
                End With
            Next
        Next
    Next
End Sub

The macro steps through each data label for every data series on every chart and (again) replaces any instances of whatever is in sOld with whatever is in sNew.

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 (9262) 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 in Text Boxes.

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

Setting Embellishment Spacing in the Equation Editor

The equation editor is a great tool for adding mathematical equations into your document. The placement of many elements ...

Discover More

Center-column Footnotes

Ever want to change the formatting of your footnotes? This tip explains what you can and can't do in Word.

Discover More

Excel 2007 Serious Sorting (Table of Contents)

Sorting data means that you organize it in whatever order you desire. Excel's sorting feature can be used in a variety of ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Finding Text in Text Boxes

Want to search for text that may appear in a text box rather than in a regular worksheet cell? You can only perform the ...

Discover More

Searching for Leading Apostrophes

Take a look at the Formula bar when you select a cell that contains text, and you may see an apostrophe at the beginning ...

Discover More

Wildcards in 'Replace With' Text

When doing searches in Excel, you can use wildcard characters in the specification of what you are searching. However, ...

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 five more than 3?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.