Sorting by Highlighting

by Allen Wyatt
(last updated August 20, 2018)


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, and 2013.

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


Conditionally Making a Sound

Need to have a sound played if a certain condition is met? It is rather easy to do if you use a user-defined function to ...

Discover More

Selecting Fonts for a Chart

When formatting a chart, you might want to change the characteristics of the font used in various chart elements. This ...

Discover More

Mysterious Blue Line between Paragraphs

Do you ever have mysterious lines show up between paragraphs either on your screen or on your printouts? It could be ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Sorting a Text Selection

Word gives you the option to sort selected groups of text. You can do text, date or number sorts on whole paragraphs or ...

Discover More

Controlling How Word Sorts Text

Word has a very orderly way in which it sorts information, but that orderly method may not meet what you need to have ...

Discover More

Sorting Tabular Tables

Some people like to format simple tables using tabs instead of using Word's table editor. When it comes time to sort such ...

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}] 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 one more than 1?

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.

Newest Tips

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.