The Excel Sort command just doesn’t work in the case of merged cells of different sizes. First of all, you need to unmerge them all. Or, you can make all the merged cells of the same size to sort them. In this article, you will learn 2 ways to sort merged cells of different sizes in Excel with ease.
How to Sort Merged Cells of Different Sizes in Excel (2 Easy Ways)
1. Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Commands
The data table in the following picture has merged cells of different sizes.
Now let’s try to sort the state names alphabetically.
For that, select all the State names and then click on the A to Z icon, in the Sort & Filter group on the Data tab.
Microsoft Excel will show a warning box saying, “To do this, all the merged cells need to be the same size.”
To fix this problem, we need to unmerge all the cells first.
For that,
❶ Select all the merged cells again.
❷ Then go to Home >> Alignment >> Merge & Center >> Unmerge Cells.
All the cells will be unmerged and it will look like this:
❸ Now put your mouse cursor at the right-bottom corner of each of the cells having the State names and double-click on the Fill Handle icon to AutoFil.
❹ After that, select the range B5:E13.
❺ Then go to Data >> Sort & Filter >> Sort.
The Sort dialog box will appear.
❻ Select Column B near the Sort by and hit the OK button.
Now the whole data table will be sorted based on Column B.
❼ Now merge each of the cells having the state names manually.
Read More: How to Sort Merged Cells in Excel
2. Use VBA Code to Sort Merged Cells of Different Sizes
You can use a VBA code to unmerge all the cells in a worksheet. Then you can sort all the cells and merge them back. That’s that you can sort merged cells of different sizes.
Now follow the steps below to learn in detail.
❶ Press ALT + F11 to open the VBA Editor.
❷ Then, go to Insert >> Module.
❸ Insert the following code in the VBA Editor.
Sub UnmergeCells()
Range("B5:D13").Select
Selection.UnMerge
Range("B5").Select
End Sub
Breakdown of the Code
- Here, I specified a range to select.
- Then I used the UnMerge property to unmerge each of the cells in the selected area.
- Then I used the Range and Select properties to make the selection in cell B5.
❹ Now go back to your worksheet and press ALT + F8.
The Macro dialog box will appear.
❺ Hit the Run button for now.
All the merged cells will be unmerged instantly.
❻ Now put your mouse cursor at the right-bottom corner of each of the cells having the State names and double-click on the Fill Handle icon to AutoFil.
❼ After that, select the Entire data table. Then go to Data >> Sort & Filter >> Sort.
The Sort dialog box will appear.
❽ Select Column B near the Sory by and hit the OK button.
Now the whole data table will be sorted based on Column B.
❾ Now merge each of the cells having the State names manually.
Read More: How to Sort Unique List in Excel
Practice Section
You will get an Excel sheet like the following screenshot, at the end of the provided Excel file. Where you can practice all the methods discussed in this article.
Download Practice Workbook
You can download the Excel file from the following link and practice along with it.
Conclusion
To sum up, we have discussed 2 ways to sort merged cells of different sizes in Excel. You are recommended to download the practice workbook attached along with this article and practice all the methods with that. And don’t hesitate to ask any questions in the comment section below. We will try to respond to all the relevant queries. And please visit our website Exceldemy to explore more.
Related Articles
- How to Sort by Name in Excel
- How to Sort by Last Name in Excel
- How to Sort Duplicates in Excel
- How to Sort Numbers in Excel
- How to Put Numbers in Numerical Order in Excel
- How to Sort Numbers with Letter Suffix in Excel
- How to Sort in Excel by Number of Characters
- How to Arrange Numbers in Ascending Order in Excel Using Formula
<< Go Back to Sort in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!