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


Rounding To the Nearest Even Integer

Do you need your numbers to be rounded to an even integer value? How you accomplish the task depends on the nature of the ...

Discover More

Moving Custom Formats to Number Formatting Categories

Moving your custom formats into a formatting category other than "custom" isn't something you can do in Excel. Here's ...

Discover More

Converting Text to Values

When you import information originating in a different program, Excel may not do the best job at figuring out what ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Odd Sorting

Word is great at sorting simple information in tables and paragraphs. If you have more complex information (such as ...

Discover More

Sorting Text

Word makes it easy to sort the information that is contained in your document. Here's how to accomplish this.

Discover More

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

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 less than 8?

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.