Finding and Replacing when Only a Portion of the Text is Superscripted

Written by Allen Wyatt (last updated May 20, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Leo need to search for two superscripted digits followed by a period and replace it with a period followed by the superscripted digits. Only the digits are superscripted, not the period. Leo wonders if this is something that can be done with Find and Replace, or if he needs to use a macro.

The answer is "yes," but it depends on the nature of the text and what you are trying to do. (I know that answer sounds squirrelly, but stick with me here.) The nature of the problem here is that there is mixed formatting in what you are looking for. The traditional approach to this type of problem is to do multiple passes of Find and Replace to get to your result.

The fact that you are dealing with digits, however, may allow you to do the Find and Replace in a single pass, without regard to the mixed formatting. If the only time your text contains two digits followed by a period is when the two digits are superscripted, then you can use Find and Replace to do the work. Just follow these steps:

  1. Press Ctrl+H. Word displays the Replace tab of the Find and Replace dialog box.
  2. Click the More button, if it is available. (See Figure 1.)
  3. Figure 1. The Replace tab of the Find and Replace dialog box.

  4. Make sure the Use Wildcards check box is selected.
  5. Enter the following in the Find What box: ([0-9]{2})(.)
  6. Enter the following in the Replace With box: \2\1
  7. Click Replace All.

This replaces all occurrences of two digits followed by a period with a period followed by those same digits. If you want to replace only some of them, you can, in step 6, step through each match instead of replacing all of them. This works because you are not seeking to do any formatting change with the Find and Replace operation, so the original formatting of the characters remains the same.

If you want to replace everything and make sure that the two digits are superscripted, then you'll need to resort to a macro. The following is an example of one that should do the trick:

Sub SwapSupDigits()
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "([0-9]{2})(.)"
        .Replacement.Text = "\2\1"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Do While Selection.Find.Execute
        With Selection
            .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
            If .Font.Superscript = True Then
                ' Found superscript numbers
                .Collapse Direction:=wdCollapseStart
                .Find.Execute Replace:=wdReplaceOne
            End If
            .Collapse Direction:=wdCollapseEnd
        End With
    Loop
End Sub

The first portion of the macro sets up the search the same as the manual steps did, earlier. If a match is found, then the macro looks at the digits and swaps the position with the period only if the digits are superscripted.

I started by saying that the answer to the problem depends on the nature of the text you are working with. There is one other time when the above solutions won't be satisfactory—if the superscripted digits are actually footnote or endnote references. While these appear to be superscripted digits, they are really superscripted markers that indicate where the footnote or endnote is anchored. Treating them as regular digits (as the previous approaches do) won't result in any matches because they aren't digits.

If that is the type of text you are dealing with, then the following usage of Find and Replace should work fine:

  1. Press Ctrl+H. Word displays the Replace tab of the Find and Replace dialog box.
  2. Click the More button, if it is available.
  3. Make sure the Use Wildcards check box is selected.
  4. Enter the following in the Find What box: (^2)(.)
  5. Enter the following in the Replace With box: \2\1
  6. Click Replace All.

Note, in step 4, that the first part of what you are looking for is (^2). This is a special code, surrounded by parentheses, that will match any footnote or endnote marker. The code is undocumented (or, I haven't been able to find any official documentation about it in the past two decades) and it only works if you are doing a wild card search.

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 (13918) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.

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 a Default for the Object Browser

Does it bother you that when you press Ctrl+Page Up or Ctrl+Page Down you aren't always taken to the top of the previous ...

Discover More

Comparing Strings

When writing a macro, a common task is the need to compare two strings. You can do this by "normalizing" the strings, as ...

Discover More

Turning Off the 'Welcome Back' Notice

When you open a document that you previously edited, Word displays a message the right side of the screen about jumping ...

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 (ribbon)

Changing Formatting for a Portion of Found Text

The Find and Replace capabilities of Word are quite powerful. If you want to change the formatting of just a part of text ...

Discover More

Getting Rid of Hidden Text in Many Files

Hidden text is a great boon if you want to make sure something doesn't show up on the screen or on a printout. If you ...

Discover More

Searching for Special Characters

When using the Find and Replace feature of Word, you can search for more than plain text. You can also search for ...

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