Forum Discussion
Sort by merged cell size
What you are trying is something hypothetical but yes it has a solution also.
- Let me remind that if you are thinking that the Merged cell looking taller has different Height or Excel increases it's Height then you are wrong.
- Merged cell's Height is as similar to a normal cell's.
Now how to Sort data in Merged Cells,, has tricky solution.
- Press F5, you get dialogue box.
- Hit Special then click Blank.
You find all blank cells,, are part of Merged cells been selected.
Now type a = sign into the Formula Bar.
Write the reference the cell which locates above the first blank cell.
And press Ctrl + Enter button simultaneously.
You find all blank cells are filled with the value above.
Now select the Column & SORT.
Another is the better and is faster too, is VBA Macro.
Private Sub SortMergerdCells()
Dim MyRange As Range
Set MyRange = Range("A2:A21")
On Error Resume Next
With MyRange
.UnMerge
.Resize(.Rows.Count, 1).SpecialCells(xlBlanks).Formula = "=R[-1]C"
.Sort Key1:=.Cells(1, 1)
Range("VBA_RecFmt").Copy
.PasteSpecial Paste:=xlPasteFormats
End With
Call Duplicate
End Sub
Sub Duplicate()
Dim a As Long
For a = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If WorksheetFunction.CountIf(Range("A2:A" & a), Cells(a, 1)) > 1 Then Rows(a).Delete
Next
End Sub
How it works:
Above are two Macro.
- Either press ALT+F11 or select the Sheet TAB, then Right Click.
- From Menu hit View Code.
Now VB editor will open.
- Copy & Paste this code (Excel will automatically dived them into two).
- Now go to Developer TAB, hit Macro & select the Macro from the List and hit RUN.
You find the Data has been Sorted.
N.B. In first VBA code check this Range("A2:A21") , is data Range has value in both Merged and in Un-Merged cells, and you need to adjust it as needed.
- Rajesh_SinhaJun 03, 2021Iron ContributorBoth of my suggested methods are working,, read instruction while using ,, will work ,, if my solution works then you may accept it as Best Answer as well Like & keep asking ☺