Sorting by Highlighting

by Allen Wyatt
(last updated May 18, 2020)


Tim has a list of items in a Word document. Each item is in its own paragraph (Enter at the end) and not in a table. Some of the items (paragraphs) have highlighting applied to them. Tim wonders if there is a way to sort the paragraphs so that the highlighted paragraphs are together. In other words, he needs to sort by highlight as the primary sort key.

Word can sort by many things but sorting by highlighting is not one of those things. However, Find & Replace can search for highlighting. One method would be to use Find & Replace to prefix each highlighted paragraph with a unique keyword, run Find & Replace again to prefix non-highlighted paragraphs with another keyword, then sort the document using the first word as the first key so that the highlighted paragraphs are together. Afterwards run Find & Replace to remove the two special keywords. Obviously, this method is tricky to set up and requires several steps.

Another approach is to simply sort all the paragraphs, without regard to the highlighting. Once that is done, you can use a macro to move highlighted paragraphs to the start of the document. The highlighted paragraphs will appear in the sorted order they were in the document.

Sub MoveHighlightedParas()
    Dim paraMax As Long
    Dim paraStart As Long
    Dim j As Long
    Dim r As Range

    With ActiveDocument
        paraMax = .Paragraphs.Count
        paraStart = 0
        j = paraMax
        Do While j > paraStart
            If .Paragraphs(j).Range.HighlightColorIndex <> wdNoHighlight Then
                Set r = .Content
                paraStart = paraStart + 1
                j = j - 1
            End If
    End With
End Sub


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 (13272) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 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. ...


Creating Multiple Highlighter Tools

Some people, while developing documents, like to use the Highlighter tool quite a bit. It can quickly get monotonous, ...

Discover More

Adjusting the Order of Items in a Chart Legend

When charting your data, a legend is always a nice finishing touch. You may want to change the order in which items ...

Discover More

Transposing Two Words

A common editing task is to transpose two adjacent words, so that their order is changed. While the task is common, there ...

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)

Changing Sort Order

When sorting information, Word follows some pretty strict rules. If you want to modify how those rules are applied, you ...

Discover More

Alphabetizing By Last Name

Sorting lists of names by last name is easy if they are listed in a LAST, FIRST order. But what if the names are in FIRST ...

Discover More

Sorting by Headings

Headings are a great way to organize your document. If, after getting your headings in place, you want to sort by those ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


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 six more than 7?

2020-01-28 06:49:56


Dear Mr. Allen Wyatt,

I want a code which will identify the same heading from multiple word files and highlight the text under these headings.
So headings are the same e.g. find "LEARNING OBJECTIVE" and highlight different objectives under this heading from multiple word files at the same time with macro.

Please help.


2016-08-18 15:33:39


In word 2010 I cannot sort a list by the last word in each paragraph. Each paragraph (separated by an Enter), has different number of words.
How can I sort this list by the LAST word in each paragraph? I need to do this with a long list of names with varying numbers of words in each paragraph.

Please give me some help.


2015-02-12 02:55:03



This works great! Is it possible to sort the opposite way? - The highlighted paragraphs in the bottom instead of in the top?

2014-10-06 10:02:29

Jennifer Thomas

Kathyrn, I feel your pain -- I was in the same situation not so long ago. But Wyatt is right in that many of the solutions we need are simply not available in Word, so we have to write them ourselves. If you are at the point where you can sort-of-understand macros you read but don't really know how to tweak them or manipulate them in the VBA window, I'd recommend a beginning or intermediate class in VBA for Word (paid or online) -- that got me to the point where I could at least work with and make minor edits to what I copied from the 'net and has saved me a lot of time and tears ever since!

2014-10-05 12:13:51



This site (which has thousands of tips available) is about evenly mixed between tips that use VBA/macros and those that don't. For some tips macros MUST be used because that is the only way to accomplish what someone is asking -- such as with this particular tip.

That being said, the book offered when first joining the newsletter list is intended as a compendium of all the tips related to macros. If you want to learn macros from scratch -- which it sounds like you do -- then this book will be your best bet:

It is a tutorial on how to use macros and presumes no beginning level of knowledge about macros.


2014-10-05 11:29:12


Following up on Charles Stewart's question and Damear's reply "this is VBA, or Visual Basic for Applications, MS Office's very own programming language" -- This site would be better labeled as "VBA for Word" or something like that." Not so useful for people who are not programmers--I have not read one tip that tells where or how in WORD to use this VBA code. Or even mentions in the tip text that VBA is what it's talking about. (Same with the book offered if you register with the site.) Maybe I missed something?

That said, YouTube might have some videos, or Amazon a book, that may be helpful.

2014-10-04 13:34:34


It is so much easier and faster and foolproof to simply use Alt + Shift + Up/Down Arrow keys to relocate (sort) entire paragraphs when the Cursor is present anywhere within the text to be moved.

2014-10-04 07:38:17


Charles Stewart, this is VBA, or Visual Basic for Applications, MS Office's very own programming language.

2014-10-04 05:34:15

Charles Stewart

What is the programing language (or macro language) used to develop the subroutine used in this example? I have programmed in many languages so I already understand it in general but I want specific of the language structure needed to detail program myself - Where could I find a quick reference?

2014-10-04 04:36:20

Ken Endacott

If you want to retain the highlighted paragraphs in the document at the same time place copies at the start of the document, change the line:




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.


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.