Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
In Word, how do I readily sort a string of numbers separated by commas?
My string of numbers is 32, 29, 10, 30, 40, 39, 48, 12, 42, 41, 38, 18. How can I sort this from smallest to largest most readily?
I clicked OK as pictured below, but nothing happened. Then I picked Headings, whilst keeping all the other settings, but again nothing happened. Then I picked Field 1, while keeping all the other settings, but again nothing happened. Why?
I am not asking about unproductive methods like brute force. 'Sort Text' worked when I hit "Enter", and started each number on a new line. But this gruntwork is impractical, if the string contains many numbers.
2 answers
The Sort Text function shown in the snapshot is intended to sort lists. In Microsoft Word, a list has each element member in a new line (paragraph). Considering this:
- Convert the numbers separated by commas into a list.
This could be done by using search and replace, replacing the commas and spaces with a paragraph mark. Use
^p
in the replace text box for a paragraph in the search and replace dialog. - Select the list
- Open Sort text
- Verify that the options are Paragraphs, Number and Ascending, then click OK.
- If needed, replace the paragraph marks with commas and spaces. Use
^p
in the find text box for a paragraph in the search and replace dialog.
NOTES:
While the default view is the Print Layout view, working on it might make it difficult to identify when a line is caused by a paragraph, a line break, page margins or other objects.
I'm not including screenshots as I'm using Word for Mac. The dialogs are different but the Sort Text feature work the same way. On the other hand, the official help article already includes snapshots, and it's available for three platforms Windows, Mac and Web : Sort a list alphabetically in Word.
0 comment threads
You can't do that in Word.
Word's Sort command operates on "fields" in separate rows. It is nominally for Tables, but if the selected data is not in an actual Table then it treats each row of text as if it were a row of a Table. Note that each row here is a full Paragraph, defined by a hard return, not a line as defined by text flowing between margins.
There is an option for separating fields by commas, but that is for selecting which field within each row is sorted. For example, if your text is:
a,1,2 b,10,20 c,5,10 d,7,25
then if you sort by Paragraph or by Field 1 then it will sort as shown. If you select Field 2 then it will sort to:
a,1,2 c,5,10 d,7,25 b,10,20
and if you select Field 3 then it will sort to:
a,1,2 c,5,10 b,10,20 d,7,25
It just doesn't seem to have any way to sort within a row. This is consistent with the general and historical usage of CSV/comma-delimited data as database data - each row is a record and sorting is typically via a numbered field within the rows.
If you have a large pre-existing data set consisting of a single long row of comma-delimited data, you can search/replace to change , to Paragraph Mark (select from Special or enter ^p) and then Sort the results.
1 comment thread