Selective Formatting in Replacements

Written by Allen Wyatt (last updated March 18, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


Even though you cannot be selective in your searching (previous tip), Word can be much more flexible when it comes to actually replacing information. For instance, let's say you have a document in which you have many instances of the characters X45. If you want to find these characters and replace them with a regular X and a superscripted 45, there are several ways you can go about it.

The first method involves a two-step search and replace. You can follow these general steps:

  1. Search for the X45 string and replace all occurrences with X$%$%. The idea here is that $%$% is a string which is not used elsewhere in your document.
  2. Search for all occurrences of $%$% and replace it with a superscripted 45.

It doesn't take terribly long to do these two steps, and if you need to do them in multiple documents you can automate the process by recording a little macro that does them.

Another way to approach the problem is to create a little macro that does the actual search and replace in one pass of the document. The macro can find all occurrences of X45, select just the 45 part, make it superscript, and then go on to the next occurrence. The following macro does just that:

Sub DoX45()
    Dim oRng As Range
    With Selection
        .HomeKey unit:=wdStory
        With .Find
            .ClearFormatting
            .Forward = True
            .text = "X45"
            .Execute
            While .Found
                Set oRng = ActiveDocument.Range _
                (Start:=Selection.Range.Start + 1, _
                  End:=Selection.Range.End)
                oRng.Font.Superscript = True
                oRng.Start = oRng.End
                .Execute
            Wend
        End With
    End With
End Sub

Finally, if you don't particularly care for macros, there is an even easier solution:

  1. Format the first instance of X45 the way you want it to appear.
  2. Select the instance and press Ctrl+C. The formatted version is now in the Clipboard.
  3. Press Ctrl+H to display the Replace tab of the Find and Replace dialog box. (See Figure 1.)
  4. Figure 1. The Replace tab of the Find and Replace dialog box.

  5. In the Find What box, type X45.
  6. In the Replace With box, type ^c.
  7. Click on Replace All.

By following these steps, Word replaces all instances of X45 with the contents of the Clipboard, which happens to be the formatted version you want to use. In other words, your text is formatted in one search and replace operation.

Note:

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

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1553) applies to Microsoft Word 97, 2000, 2002, and 2003.

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

Paragraph Numbers in Headers or Footers

If your documents routinely use numbered paragraphs, you may want to place the number of the page's first paragraph in ...

Discover More

Smart Quotes are Incorrectly Replaced

Not able to replace smart quotes as you want? Here are some ways that you can be sure that every smart quote is changed, ...

Discover More

Unwanted Cover Pages with Print Jobs

When you print a document, do you get more than you bargained for? If you get extra pages printed either before or within ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (menu)

Ignoring Accented Characters in Searches

When writing in non-English languages, there can be many variations of accented characters that are used in a word. You ...

Discover More

Selective Formatting in Searches

Need to search for text that has different formatting within the search term? Word can't handle something this complex, ...

Discover More

Replacing Some Smart Quotes

Smart quotes look great in a document, but may not be right for all instances of quote marks or apostrophes. If you need ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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 2 + 2?

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

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.