Displaying the Number of Replacements Made

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


When manually using Find and Replace, Barry notes that it finishes with a message as to how many replacements were made. He wonders if he can instruct Word to display the same message when doing a Find and Replace in a macro.

The short answer is no, you cannot access the count that is displayed by Word after it does its Find and Replace. There is a workaround, however, that may be usable.

When you normally do a Find and Replace in a macro, you use code similar to this:

With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "old text"
    .Replacement.Text = "new text"
    .Forward = True
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .MatchByte = False
    .MatchFuzzy = False
    .Wrap = wdFindStop
    .Execute Replace:=wdReplaceAll
End With

Upon executing the code, all instances of "old text" are replaced with "new text." However, because it is being run in a macro, Word doesn't display a message, as Barry notes. VBA doesn't allow any access to the number of changes made by the replace operation.

The way around this is to make a slight structural change, in this manner:

lCount = 0
With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "old text"
    .Replacement.Text = "new text"
    .Forward = True
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .MatchByte = False
    .MatchFuzzy = False
    .Wrap = wdFindStop

    Do While .Execute Replace:=wdReplaceOne
        lCount = lCount + 1
    Loop
End With

The key change here is that wdReplaceAll was changed to wdReplaceOne, so VBA makes one change at a time. For each pass through the Do While loop, a single replacement is made and the lCount variable is incremented. When this code is complete, lCount will contain the number of replacements made, which meets Barry's need.

The different approach (wdReplaceOne vs. wdReplaceAll) does come with a tradeoff, however—it is a bit slower. Unless your document is seriously long or has a ton of replacements to be made, the speed difference should be negligible.

Finally, understand that as presented in this tip, the Find and Replace operation affects only the main document content. If you also want the operation to affect content in headers, footers, footnotes, endnotes, and the like, you would need to step through the StoryRange collection to affect everything else. That said, a manual Find and Replace (what Barry is comparing to) also only affects the main document unless you specifically direct Word to affect other document areas.

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

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

Changing Styles

Styles are a great boon to making your documents look better and making them easier to update. You can change the ...

Discover More

Unwanted Cover Pages with Print Jobs

When you print a document, do you get more than you bargained for? If you get extra pages printed either before or within ...

Discover More

Easily Dividing Values by 1000

Sometimes the data in a worksheet isn't in the exact format desired. If you want to divide your values by 1,000, there ...

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 2019. Spend more time working and less time trying to figure it all out! Check out Word 2019 For Dummies today!

More WordTips (ribbon)

Replacing a Colon in a Sequence

Sometimes you'll run across the need to replace a very specific sequence of characters in your document. It is for these ...

Discover More

Using Search Text in the Replacement

When you use the Find and Replace tool in Word, you may want to include what you searched for in the replacement text. ...

Discover More

Special Differences when Searching

Word includes two different search engines. Which search engine you choose to use will dictate what Word shows as ...

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