How to Group Identical Word Table Rows Without Alphabetical Sorting
Question details
The user needs to group rows in a Word table that have identical values in the first column, but wants to maintain a specific custom order rather than defaulting to alphabetical or numerical sorting.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Organizing large tables where grouping specific rows together is necessary, but standard A-Z sorting disrupts the logical sequence.
- Observed behavior
- Using default sorting tools arranges the table strictly alphabetically or numerically, which ruins the desired custom group order.
Always save a backup copy of your Word document before running VBA macros or performing bulk sorting, as complex table rearrangements cannot always be easily undone.
Use a VBA Macro to Group Rows Automatically
Assigns a temporary grouping number based on unique values in the first column, sorts the rows, and then cleans up the numbers. Best for large or frequently updated documents.
By utilizing a VBA macro, you can automate the process of grouping identical table rows without having to manually type custom prefixes. The script assigns hidden values to unique entries to maintain your desired order, groups them, and removes the temporary data.
Go to File > Options > Customize Ribbon. In the right pane, check the box for 'Developer' and click OK to make the Developer tab visible on your ribbon.
Navigate to the Developer tab and click on 'Visual Basic', or press Alt + F11 to open the VBA editor.
In the VBA editor, click Insert > Module. Paste the macro code designed to assign sequential index numbers to your unique column values, sort the table based on those index numbers, and then clear the inserted values.
Place your cursor inside the table you want to sort. Press Alt + F8, select your grouping macro from the list, and click Run. The table will automatically group identical items while retaining your custom logical flow.

Manually Add Number Prefixes for Custom Sorting
A simple workaround without code: manually add numbers to the cells to force a specific sort order, then delete them.
Manage and Sort Tables Easily with WPS Writer
WPS Office provides robust table management tools and VBA support to help you organize data exactly how you need it. You can seamlessly group and sort identical rows while keeping your document layout intact.
- 1. Open Your Document: Launch WPS Writer and open the .docx file containing the table you need to group.
- 2. Access Table Tools: Click anywhere inside your table to reveal the 'Table Tools' tab on the top ribbon.
- 3. Sort Your Data: Click the 'Sort' button to organize your table data using custom columns, types, and ascending or descending orders.
- 4. Automate with Macros: For complex grouping tasks, switch to the Developer tab to run custom VBA scripts seamlessly within WPS Writer.

Frequently Asked Questions
Why does Word always sort my tables alphabetically?
Word's default sort tool uses alphabetical (A-Z) or numerical (0-9) logic. It does not have a built-in 'group by' function that bypasses standard sorting rules, which is why workarounds like custom prefixes or macros are necessary for specific grouping.
Can I sort rows based on cell background color instead?
No, Microsoft Word does not natively support sorting tables by cell background or font color. To do this, you would need to copy the table to Excel, sort it by color, and paste it back into Word.
Will sorting a Word table mess up my merged cells?
Yes, sorting tables containing horizontally or vertically merged cells often causes errors or breaks the document layout. It is highly recommended to unmerge all cells before sorting, and merge them again afterward.
Can I use Excel to sort Word table data and paste it back?
Absolutely. Copying your Word table into Excel gives you access to custom sort lists, advanced filtering, and grouping functions. Once the rows are organized to your liking, simply copy the data and paste it back into your Word document.




