Sorting Text in InDesign
Stop cutting and pasting to rearrange text in InDesign! You have much better options.

This article appears in Issue 143 of InDesign Magazine.
Every InDesign user will inevitably need to sort lists and tables. Here are some tools you should have on hand for those tasks.
Sooner or later, as an InDesign user, you will find yourself completely in a state of creative flow, designing beautiful layouts, cranking out pages with grace and precision. And then, out of nowhere, you will be asked to alphabetize a list.
Cue the record scratch sound.
In the vast scheme of things, sorting text in InDesign (or prior to placing it in InDesign) is not the largest problem you’ll ever face. But it’s one of those little unavoidable tasks that can knock you out of your groove because, as you probably already know, nothing in InDesign’s core program will sort your text for you. Knowing that, you could simply rearrange your list manually, cutting and pasting each item line by line.
Unfortunately, that old-school method is boring, voraciously consumes time, and introduces the risk of errors. It’s also one thing to sort a few simple lines, but what if your client gives you text of hundreds of addresses sorted by zip code and you need to deliver a book alphabetized by last name? And what if some of those names start with non-English glyphs? Suddenly the brute force approach of manual copy and paste just sounds brutal. In that case, there’s only one acceptable solution: Make your computer do the work for you.
Scripts to the Rescue
Although InDesign won’t sort text by itself, Adobe quietly installs something that will allow you to do so: a script. Fortunately, you don’t need to know how to code in order to use one!
InDesign installs a number of useful scripts automatically, and you can access them by choosing Window > Utilities > Scripts > Samples and then selecting what language you will be using. I tend to use JavaScript, which works on both macOS and Windows.
The simplest sort
For simple sorting of paragraphs, you can use SortParagraphs, one of the default scripts that comes with InDesign.
First, select the text you want to sort (Figure 1).

Figure 1. The SortParagraphs script comes with InDesign.
In the Scripts panel, double-click SortParagraphs.jsx to run it. Presto! (Figure 2)

Figure 2. SortParagraphs does the job in one click.
You can sort your text alphabetically from A to Z (ascending) or from Z to A (descending). The script also offers the option to ignore spaces in your sort (Figure 3).

Figure 3. You can ignore spaces and get a different sort result.
Sorting on steroids
The SortParagraphs script has its uses, but what if your needs go beyond the basics? Now’s the time to get to know what’s out there if you ever need it, thanks to the dedicated community of InDesign scripters who have released amazing code into the wild for you to use.
One such power scripter is Peter Kahrel, whose incredible collection of InDesign scripts, including his Language Aware Paragraph Sorter, is now hosted at here at CreativePro. Like the name suggests, Peter’s script can correctly alphabetize text in multiple languages.
For designers working on foreign-language texts, this script is fluent. Out of the gate, it offers 59 defaults for languages or contexts (Figure 4). If you need something else, the settings are easily modified by editing an associated text file.

Figure 4. Peter Kahrel’s Language Aware Paragraph Sorter offers 59 presets for languages and their variants.
Sort more precisely
Even if you won’t ever sort text in another language, this script still has a place in your toolbox. How many times have you looked for an item in a list and found it was there, alphabetized under T for the? Kahrel’s script can ignore specific words at the start of the line (Figure 5).

Figure 5. With Language Aware Paragraph Sorter, you can select words to ignore, like The, as seen in the sorted list here.
For example, what if you want to sort a list by last name and the last name follows the first name? If you have just a few exceptions, you can add those to the “ignore words” field. Another way is to use this script’s ability to sort by character style. Here’s how.
Create a character style specifically for this sorting task. Set it to change the color to a temporary color that is obviously visible to you. (I’ll use magenta.)
Apply the character style to all the text you’re sorting (in this case, the last name).
For first names (which you want to ignore), select up through the space before the last name and apply [None] (Figure 6). This will leave only the first names that you don’t want to sort in the original color of your text. (Yes, this is counterintuitive, but stay with me.)

Figure 6. When you want to sort a list that includes a mix of words that can’t readily be ignored in the sort, you can use Language Aware Paragraph Sorter’s Sort on Character Style option. After styling your entire list in a character style created for the purpose so you can see what you’re doing, style the words you want to ignore as [None].
Sort by your character style (Figure 7).

Figure 7. Run Language Aware Paragraph Sorter, and select your character style.
If you think you might sort this list again, you should change the color definition in the character style to match the color in your paragraph style (Figure 8). Then all you need to do is change it back to magenta so you can see what you’re doing.

Figure 8. You can keep the character style for further sorting by redefining it to match the color of its underlying paragraph style. Re-redefine the color to repeat a sort.
When you’re all done you can delete the character style—just be sure to turn off the Preserve Formatting option so any color isn’t left behind.
Among its capabilities, the script can do one of those things that you never would have thought to ask for: a “retrograde sort,” which groups lines in order of the last letters of the word. Sounds crazy, but perhaps you want to isolate and identify words that might rhyme (Figure 9). This can also be useful for putting some lists of product codes in order.

Figure 9. Retrograde sort can sort by letters from the end of the list items—an interesting way to find rhyming words. Or something.
Sorting from within
Another challenging scenario is organizing unsorted tab-delimited text from a spreadsheet or a database. How do you sort on chunks of text in the middle of a paragraph? This is one of those situations where your clients tend to think something is a whole lot easier than it really is.
Fortunately, it can be easy… but you need to use the right script. Premedia Systems offers a free script called Sort Tabbed Paragraphs, which is an adaptation of Adobe’s Sort Paragraphs script mentioned earlier in this article. Sort Tabbed Paragraphs was inspired by an article written by Sandee Cohen in Issue #44. Ten years later, it still works great.
To use it, select the text, run the script, and define the primary and secondary fields (Figure 10). The lines will sort perfectly, even if the data is embedded in the middle of the line (Figure 11).

Figure 10. Sort_Tabbed_Paragraphs can sort data delimited by tabs.

Figure 11. Tabbed paragraphs, sorted by the data highlighted with a color overlay
Another script, SmartSort, from Marc Autret of Indiscripts, is designed to preserve text formatting and offers similar multilingual capabilities (Figure 12). As near as I can tell, it’s the only script in existence that can sort paragraphs numerically—that is, where 2 always follows 1. The other scripts will treat numerals alphabetically, so when you run them you’ll get a list that looks like 1, 10, 11, 12, 13, 2, 20, 201.

Figure 12. Smart Sort can numerically sort lines of numbered text.
Table Games
What if the text you need to sort is not multiple paragraphs but rows in a table? The scripts I’ve mentioned above won’t help you. But happily, there are other solutions that can do the trick.
If your tables are meticulously formatted with table styles (and they are, aren’t they?), here’s the lowest-tech method:
Convert table to text by selecting the entire thing and choosing Table > Convert Table to Text (Figure 13).

Figure 13. Simple sorting of tables can be done easily when your tables are styled meticulously.
Sort the rows using one of the aforementioned techniques (Figure 14).

Figure 14. Use one of the text-sorting methods to sort the text before converting the text to a table, then applying your cell and table styles.
Convert text back to a table, applying your table style (bet you’re glad you used styles for everything now). Your table should be easily and quickly restored to its former glory with the rows properly sorted.
This certainly works, but you can lose some table formatting in some cases. Instead, there’s an even easier method you can use. (If you guessed it was a script, go ahead and give yourself a pat on the back. If you guessed it was a script written by Peter Kahrel, give yourself two pats.) It’s simply called Table Sort, and it swiftly sorts tabular data any way you like: ascending or descending, alphabetical or numerically (Figure 15).

Figure 15. Table Sort provides a powerful tool to manipulate data within tables.
Until this point, all the scripts I’ve mentioned are free to download. However, there are also some commercial scripts that can be well worth the cost if you use them regularly. If your project uses tables with heavy need for sorting or constant revision in InDesign, or if you have any urge to go beyond sorting tables and make them perform calculations, check out DTPTools Active Tables plug-in (Figure 16). This subscription-based plug-in adds several panels of functionality for controlling tables, as well as the ability to include conditional formatting (a common feature of spreadsheets) in paragraph style definitions. With conditional formatting, your annual report financials could literally turn red automatically when you go into the red.

Figure 16. The Active Tables plug-in offers actual spreadsheet-like behavior within InDesign.
Sorting in Microsoft Word and Excel
It’s worth mentioning that two more tools for sorting your text are probably already sitting on your computer: Microsoft Word and Excel.
For sorting straight text, you can use either program.
- Copy your whole list from InDesign, and paste it into a spreadsheet or text document.
- Sort the lines. In Word, choose Table > Sort (yes, even if you aren’t sorting a table). In Excel, choose Data > Sort (Figure 17).
- Return to InDesign to paste the sorted text over the previously selected text.

Figure 17. If you’re more comfortable with Microsoft’s robust sorting capabilities, round-tripping your lines of text into Word or Excel can sort lines of text easily.
For tables, you’ll want to use Excel.
- If you’ve done any design work, make sure you create and apply a table style and cell styles.
- Copy the data from InDesign, and paste it into a new Excel worksheet.
- Select the cells, then choose Data > Sort. Copy the cells and paste them back into InDesign.
- You might need to apply [None] for cell styles, then apply your table style anew to your freshly sorted content.
If you don’t have a license for the Microsoft Office suite, LibreOffice is strong and stable multiplatform open-source software that can read and write Excel-compatible files—and it’s free!
Never Be Out of Sorts
Sorting text in InDesign is one of those skills that you won’t realize you need until you actually need it. The best projects require the least amount of invasive editing in InDesign. Ideally, your text would come to you already sorted and ready to design. Preferably, you would be able to sail through your work with exacting precision.
But this world is far from perfect, and sorting lines and data can get messy, as can darting in between InDesign and other programs to clean up text. You will want to save often. Sometimes even the best scripts can get persnickety.
Now roll up your sleeves and get sorting!
Commenting is easier and faster when you're logged in!
Leave a Reply
Recommended for you

Illustrator Downloadable: Tropical Shadow Overlay Kit
Downloadables are an exclusive benefit for CreativePro members! (Not a member ye...

Illustrator Downloadable: Summer Citrus Pattern Set
Downloadables are an exclusive benefit for CreativePro members! (Not a member ye...

InDesign Downloadable: Tables SuperGuide
Downloadables are an exclusive benefit for CreativePro members! (Not a member ye...
This is such great info! Thank you. I’m an experienced user and didn’t know about these scripts until recently. However, I have a scenario where I can’t figure out whether any of these scripts will work. I have a grid that I want to sort across the row and then move down to the next row. I’ve tried the table scripts and I’ve tried making it one long text threaded text chain. The other catch is that these are graphics with their description below. For the text version, I would need the script to ignore not only spaces, but also the anchored graphic marker and next column marker.