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

Grouping Images Changes Text Wrap to Inline

When you group images together, Word needs to figure out how to set the text wrapping for the new group. This tip ...

Discover More

Understanding ZIP Folders

Need to move a lot of information to someone else? The answer may be to store that information in a ZIP folder. Here's ...

Discover More

Pulling Apart Characters in a Long String

You can easily use formulas to pull apart text stored in a cell. For instance, if you need to pull individual characters ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Making Ctrl+F Work Traditionally

One change introduced in Word 2010 was the new navigation pane that is used for simple searching of information. This ...

Discover More

A Fast Find-Next

Want a quick, easy way to "search again" for the next occurrence of what you need? Use the technique in this tip and ...

Discover More

Changing the Position of the Dollar Sign

When you receive documents created by others, it is not unusual that you'll want to edit what they've written. 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 8 + 4?

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.