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 .Paragraphs(j).Range.Cut Set r = .Content r.Collapse r.Paste paraStart = paraStart + 1 Else j = j - 1 End If Loop End With End Sub
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.
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!
Headings are a great way to organize your document. If, after getting your headings in place, you want to sort by those ...Discover More
Word allows you to easily sort the information you store in a document. If you want to sort information as groups of ...Discover More
Word is great at sorting simple information in tables and paragraphs. If you have more complex information (such as ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.