Sort Merged Cells

Jeet_Dhillon

New Member
Joined
Jul 13, 2019
Messages
19
Friends , I am trying to Sort a Sheet but Cells are merged , i was able to record a Macro by Manually Unmerge Cells and then Merge , But this whole Process takes time and Lag.
Any Suggestions to Tune up this Code .

Thanks


"Private Sub Repairsort_Click()
RepairSort.BackColor = 9434879


Range("D30:Q64").Select
Selection.UnMerge
Range("B30:T64").Select
ActiveWorkbook.Worksheets("Forepersons Report").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Forepersons Report").Sort.SortFields.Add Key:= _
Range("B30"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Forepersons Report").Sort
.SetRange Range("B30:T64")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D30:F64").Select
Selection.Merge True
Range("G30:Q64").Select
Selection.Merge True
Range("G47:Q47").Select



End Sub"
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Instead of merging cells, you could just use wider columns and avoid the problem.
 
Upvote 0
Not much you can do with Merged cells....avoid them at any cost !!
But try

Code:
Private Sub Repairsort_Click()
Application.ScreenUpdating = False
RepairSort.BackColor = 9434879
Range("D30:Q64").UnMerge
Range("B30:T64").Select
Worksheets("Forepersons Report").Sort.SortFields.Clear
Worksheets("Forepersons Report").Sort.SortFields.Add Key:= _
Range("B30"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With Worksheets("Forepersons Report").Sort
.SetRange Range("B30:T64")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D30:F64").Merge True
Range("G30:Q64").Merge True
Range("G47:Q47").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This Solved my Problem .
Thanks ALot

Not much you can do with Merged cells....avoid them at any cost !!
But try

Code:
Private Sub Repairsort_Click()
Application.ScreenUpdating = False
RepairSort.BackColor = 9434879
Range("D30:Q64").UnMerge
Range("B30:T64").Select
Worksheets("Forepersons Report").Sort.SortFields.Clear
Worksheets("Forepersons Report").Sort.SortFields.Add Key:= _
Range("B30"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With Worksheets("Forepersons Report").Sort
.SetRange Range("B30:T64")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D30:F64").Merge True
Range("G30:Q64").Merge True
Range("G47:Q47").Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Not Possible because of Layout of Sheet .
In that case, how about formatting the cells as 'Centre across selection' as an alternative to 'Merge and centre'?

The appearance should be the same if done correctly, and it should avoid the issues with sorting.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top