Finding Text Using a Specific Highlighting Color

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


6

Amir uses different highlighting colors throughout his documents. When he uses Find and Replace to find highlighted text, it treats all highlighting colors the same. Amir would like, specifically, to use Find and Replace to locate only text highlighted in yellow, having it ignore any other highlighting color used in the document.

Before getting into how to possibly do this, it is important to discuss terms for a moment. When using the term "highlighting color," some people think that is referring to the color applied to some particular text; it is not. Highlighting doesn't change the font's color. Highlighting is accomplished by using the Text Highlight Color tool, which is available in the Font group on the Home tab of the ribbon. (See Figure 1.)

Figure 1. Word allows you to highlight text using different colors.

When you use the Find and Replace dialog box, you can specify that you want to search for text that is highlighted. (Put the insertion point in the Find box, click Format, then click Highlight.) When you click on Find Next, Word selects the next highlighted text, regardless of the color used to highlight that text. In other words, you cannot specify that you only want to find text highlighted in yellow or blue or green or any other color; it is all treated the same.

We haven't been able to find any reliable way around this. Some information we've seen indicates that Word will only find whatever highlight color is specified in the Text Highlight Color tool, but this is not true. Other folks have indicated that if you select some highlighted text (that is highlighted with the color you want to find) before displaying the Find and Replace dialog box, only that highlight color will be found when you click Find Next. This, too, is not true. In all cases, Find Next will find any highlighted text, irrespective of color used for highlighting.

The only way around this is to use a macro to do the finding. VBA allows you to detect the color used to highlight text, which is why this approach will work. The following macro uses Find and Replace to do the finding, but then it checks to see what the HighlightColorIndex property is for what was found. If it is equal to wdYellow (an enumeration for the color yellow), then the text is selected and the macro is exited.

Sub FindNextYellow()
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = ""
        .MatchWildcards = False
        .Forward = True
        .Wrap = wdFindContinue
        .Highlight = True
        Do
            .Execute
        Loop Until Selection.Range.HighlightColorIndex = wdYellow _
          Or Not .Found
        Selection.Range.Select
    End With
End Sub

You can search for different colors simply by changing the wdYellow enumeration to the enumeration for whatever color you want.

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 (13552) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 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

Inserting Special Spaces

Do you need to frequently add en spaces and em spaces to your documents? You can add special tools to Word that make ...

Discover More

Unhiding Columns that are Persistently Hidden

If you were trying to format a worksheet and nothing you did could make the first two columns appear, would you be ...

Discover More

Conditionally Deleting Rows

Want to delete a bunch of rows in a worksheet based on the value in a certain cell of each row? There are a couple of ...

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)

Converting Text Inside Double Asterisks to Bold

In plain-text documents, it is not uncommon to see asterisks used around text to indicate what should be considered bold ...

Discover More

Finding and Deleting Rows

Got a table that contains rows you want to delete? Deleting one or two rows in a table is easy; deleting a bunch of rows ...

Discover More

Changing European Dates to US Dates

Want to change the order of the day and month in a date? This tip shows you how you can do so using the Find and Replace ...

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 eight more than 9?

2021-05-21 06:52:23

Semacovschi Constantin Dorin

Thanks!


2020-07-16 04:09:36

PeterH

Thanks a lot for a great idea! We receive documents from multiple authors, so I modified it slightly to show all highlights regardless the color used, because in addition to yellow color occasionally also other bright colors like green, cyan, red are used, so my condition is general - background is not white - I hope it will not be understood as politically incorrect :-( User can customize quick access toolbar with a button to trigger FindYellow macro to simplify its usage. And if whole doc is clear, it displays a message, otherwise user cannot be sure whether macro really did something. Stay safe, Peter.


Sub FindYellow()
'
' FindYellow Macro
'
'
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.MatchWildcards = False
.Forward = True
.Wrap = wdFindContinue
.Highlight = True
Do
.Execute

Loop Until Selection.Range.HighlightColorIndex <> wdWhite _
Or Not .Found
If Not .Found Then MsgBox ("All clear - no highlight found")

Selection.Range.Select
End With
End Sub


2020-04-28 17:21:07

Clyde

When I search for upper case 'S', Word finds all of them and highlights them in yellow. How do I change that yellow to red or blue? (I do not want to change the actual text, just the highlight for a search).


2019-05-21 10:24:12

Claire

Hi Allen

Thanks for doing that. Unfortunately, I can't get it to work; it zooms through the document at high speed, finding every instance of every highlighted text, correct colour or not and then breaks out of the macro at the end. I can't edit the bits I want to edit. Any thoughts, please?

Thank you


2018-12-17 11:25:25

Lucas

Hi Allen,
Thanks for the great tip.

I tried running your code and the problem is, if the given highlighted color I am searching for doesn't exist in the document, the code seems to search through the document 2 times and then goes into an infinite loop.

I tried setting .Wrap = wdFindStop but this doesn't seem to work with Selection.Find only Range.Find
I tried setting .Wrap = wdFindAsk and it does still prompt so the end of the document is being reached.

The Or Not .Found does not seem to be triggering either. It always remains =True.
I also tried using While .Found = True but that never turns to false either for some reason and continues to loop.

Can you please assist me with getting the .Find to exit once the end of the document is reached.

Thanks
Lucas


2018-12-17 06:43:26

Lucas

Hi Allen,
Thanks for the great tip.

I tried running your code and the problem is, if the given highlighted color I am searching for doesn't exist in the document, the code seems to search through the document 2 times and then goes into an infinite loop.

I tried setting .Wrap = wdFindStop but this doesn't seem to work with Selection.Find only Range.Find
I tried setting .Wrap = wdFindAsk and it does still prompt so the end of the document is being reached.

The Or Not .Found does not seem to be triggering either. It always remains =True.
I also tried using While .Found = True but that never turns to false either for some reason and continues to loop.

Can you please assist me with getting the .Find to exit once the end of the document is reached.

Thanks
Lucas


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.