Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Bumping Numbers in a Document.

Bumping Numbers in a Document

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


Documents often contain many words that are purposefully very similar to each other. For instance, you may have a document that references a series of part numbers, and the part numbers are all very similar to each other. Or you may reference a group of file names in which the base portion of the name is the same word, but each file name has a suffix that is a number, such as the following:

Widget01
Widget02
Widget03
Widget04
Widget05

If you ever have a need to increment the numbers within your document, the process can be very tedious and error-prone to do by hand. (Depending, of course, on the number of names you need to change.) This means that the task is a perfect candidate for being done by a macro.

As an example, the following macro, BumpNumbers, will search for all instances of the word Widget followed immediately by a two-digit number. The number will then be incremented.

Sub BumpNumbers()
    Dim J As Integer
    Dim sFindText As String
    Dim sReplaceText As String

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    For J = 98 To 1 Step -1
        sFindText = "Widget" & Right("00" & Trim(CStr(J)), 2)
        sReplaceText = "Widget" & Right("00" & Trim(CStr(J + 1)), 2)
        Selection.Find.Text = sFindText
        Selection.Find.Replacement.Text = sReplaceText
        Selection.Find.Execute Replace:=wdReplaceAll
    Next J
End Sub

Obviously, this macro is tailored to a specific need—the word Widget followed by a two-digit number. If you need to modify the macro to fit your numbering needs, you can do so by changing the For ... Next loop (so it doesn't go from 98 to 1) or by changing the text being searched for (which is assigned to the sFindText variable).

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 (12121) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Bumping Numbers in a Document.

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

Excluding Some Data from a Chart

Excel is a whiz at creating charts from your worksheet data. When the program tries to determine what should be included ...

Discover More

Full Path Names in Excel

Need to know what the full path name is for the current workbook? With a simple macro you can display the full path name ...

Discover More

Stopping Margins from Moving

Share a document with someone else, and when they open it on their system, it may look different. This tip examines some ...

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)

Determining if Num Lock is On

Need to know if the Num Lock key is on or off? You can use a short bit of macro code to figure out the state of the key.

Discover More

Printing Summary Information from a Macro

Part of the information that Word maintains about each of your documents is a summary statement, which you can define in ...

Discover More

Copying a Range of Pages in a Macro

Do you need to copy, within a macro, a range of pages? Because pages can be so fluid in Word, this can be a bit tricky. ...

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 1 + 1?

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.