Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. 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: Understanding Pattern Matching.

Understanding Pattern Matching

by Allen Wyatt
(last updated August 29, 2015)

4

The Find and Replace feature built into Word includes two completely different search engines. In the normal search engine you search for simple items, such as text or special characters. Tips related to this type of searching have been presented in other issues of WordTips.

The second search engine is the more powerful, however. It uses a search method known as pattern matching. When you use pattern matching you can search for very complex and very subtle character sequences in your document. Unfortunately, learning the pattern matching capabilities of Word can sometimes be frustrating.

How you switch between the two different search engines depends on the version of Word you are using. In most versions of Word you should pull up either the Find or Replace tabs of the Find and Replace dialog box and click on the More button. In the expanded area of the dialog box, make sure the Use Wildcards checkbox is selected. This causes Word to interpret what is in the Find What and Replace With boxes entirely differently than if the checkbox is not selected.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (263) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Understanding Pattern Matching.

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

Chapter Numbers in Indexes and TOAs

Word allows you to define prefixes for page numbers. These are often used for chapter or section numbers in a large ...

Discover More

Removing Dashes from ISBN Numbers

ISBN numbers are used to denote a unique identifier for a published book. If you remove the dashes included in an ISBN, ...

Discover More

Importing a Subset of Records

If you only want to import a portion of whatever records are in a text file, Excel provides a number of ways you can ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Special Characters in Pattern Matching

The most powerful search engine in Word use pattern matching, but the way you specify special characters in a ...

Discover More

Specifying a Number of Matches

The wild card searching capabilities of Word are amazing. One thing you can do with wild cards is to specify not only a ...

Discover More

Adding an Ellipsis to the Beginning of Some Paragraphs

The Find and Replace feature of Word is very powerful. You can even use it to add a unique character to the beginning of ...

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}] 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 0 + 4?

2019-09-21 03:02:48

Ken Endacott

Rich, the macro pauses and gives a message each time a zero result field is found. It might be quicker if the macro highlighted all the zero result fields in one pass then you can go over them individually. To do this, replace the line:

MsgBox "The field " & aField.Code & " returns zero"

with:

aRange.HighlightColorIndex = wdPink


2019-09-20 10:40:24

Rich

Ken, thanks a LOT! I'll give this a try. It's sure to save me plenty of anguish.


2019-09-14 04:34:02

Ken Endacott

Rich

Here is a macro that will do what you want.

Sub findFields()
Dim aField As Field
Dim aRange As Range
Dim k As Long
Application.Browser.Target = wdBrowseField
Do
Application.Browser.Next
Set aRange = Selection.Range
aRange.MoveEnd
k = aRange.Fields.Count
If k > 0 Then
Set aField = aRange.Fields(1)
If Trim(aField.Result.Text) = "0" Then _
MsgBox "The field " & aField.Code & " returns zero"
Else
MsgBox "No more fields found "
End If
Selection.MoveEnd
Selection.Collapse Direction:=wdCollapseEnd
Loop Until k = 0
End Sub


2019-09-13 11:30:38

Rich

I have had this problem for years and I can't seem to find a satisfactory answer for it:
I use LOTS of field codes in my documents. These documents then get forwarded to lots of people for review - people who have no idea what a field code is and have no interest in learning what it is. Naturally, when the document returns back to me there are likely going to be a lot of broken field codes, "ERROR! Reference source not found" Those are easy to deal with. I just search for "Error!" and fix them.
HOWEVER... sometimes my x-refs don't error, but they will display "0" instead. Searching for "0" is inefficient in a document full of numbers. I want to search for "0" in a FIELD, but there doesn't seem to be anyway to do that. Evidently, I can search for a field, but I need to know the name of the field and I don't think I can search for a NAMED FIELD OF A PARTICULAR VALUE ('0')

Any insight on why this happens ("0" vs "Error!") and how to fix it without slogging through page by page? Thanks.


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.

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