Written by Allen Wyatt (last updated December 3, 2022)
This tip applies to Word 97, 2000, 2002, and 2003
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 VBA 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:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (814) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Bumping Numbers in a Document.
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!
While your macro is processing the text in your document, you may need a way to determine the current page number where ...
Discover MoreNeed to figure out the hour represented by a particular time value? It's easy to do in a macro; just use the Hour ...
Discover MoreTypographical measurements are often expressed in points. There are several formatting settings that, when accessed ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments