How to Sort Merged Cells of Different Sizes in Excel (2 Easy Ways)

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.

Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

Microsoft Excel will show a warning box saying, “To do this, all the merged cells need to be the same size.”

Warning Box: Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

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.

Unmerge Cells: Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

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.

Fill Handle: Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

❹ After that, select the range B5:E13.

❺ Then go to Data >> Sort & Filter >> Sort.

Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

The Sort dialog box will appear.

❻ Select Column B near the Sort by and hit the OK button.

The Sort dialog box: Sort Merged Cells of Different Sizes Using Unmerge Cells and Sort Command

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

Use VBA Code to Sort Merged Cells of Different Sizes

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.

Macro dialog box: Use VBA Code to Sort Merged Cells of Different Sizes

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


<< Go Back to Sort in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mrinmoy Roy
Mrinmoy Roy

Mrinmoy Roy, a dedicated professional with a BSc in Electronics and Communication Engineering from Khulna University of Engineering & Technology, Bangladesh, brings over two years of expertise to the ExcelDemy project. As a prolific contributor, he has authored around 180 articles, showcasing his deep knowledge and passion for Microsoft Excel, Data Analysis, and VBA. His unwavering commitment to continuous learning, combined with versatile skills, renders him well-suited for roles in data management and spreadsheet solutions. He has interest... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo