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

Removing a List

If you have lists in your document, either bulleted or numbered, you may want to change them back to regular text at some ...

Discover More

Sorting for a Walking Tour

Want to sort addresses by even and odd numbers? By using a formula and doing a little sorting, Excel can return the ...

Discover More

Converting Time Notation to Decimal Notation

Want to convert an elapsed time, such as 8:37, to a decimal time, such as 8.62? If you know how Excel stores times ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Replacing Multiple Spaces with Tabs

If you get a document or some text that has multiple consecutive spaces used to align information, you'll undoubtedly be ...

Discover More

Initiating a New Search

I do a lot of searching in my documents. Sometimes the searches may not go exactly as I expected. Here are some things I ...

Discover More

Quick and Dirty Paragraph Count

Need to know how many paragraphs are in a document? You can use Word's Find and Replace feature to get a count quickly.

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 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.