I originally used the following to code to successfully perform my sort.
Range("g7:S1826").Select
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"k7:k1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"R7:R1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TeamSelection").Sort
.SetRange Range("g7:S1826")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Sheets("TeamSelection")
Range("g7:S1826").Select
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"k7:k1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("TeamSelection").Sort.SortFields.Add Key:=Range( _
"R7:R1826"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("TeamSelection").Sort
.SetRange Range("g7:S1826")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
However, I am looking to make my code more efficient and so I am trying to use VBA coding.
But, when I attempted to perform a sort using the following VBA code I got a "Run-time error '1004': To do this, all the merged cells need to be the same size". I don't understand why. With Sheets("TeamSelection")
.
.
.
.
.
Set sortRange = Range("G7:S1826")
Set keyCell = Range("K7")
Set keyCell2 = Range("R7")
sortRange.Sort Key1:keyCell, Order1:=xlAscending, Key2:=keyCell2, Order2:=xlAscending, Header:=xlYes
.
.
.
.
.
.
End With
Any assistance would be appreciated.
Thank you,
Don
Any assistance would be appreciated.
Thank you,
Don