Sorting a group of rows together

gymjohn

New Member
Joined
Nov 17, 2017
Messages
1
Hi, I'm not entirely sure how to phrase this and can't find the solution through search

Basically, I have a number of teams with 3 people per team. Each team member has a score which ads up to a total score, I would like to sort my teams from highest score to lowest without disrupting the teams

Ciara, 2
Emma, 4
John, 1
Total, 7

James, 3
Steve, 3
Sarah, 2
Total, 8

How do I sort this by total score while keeping team members together?

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If your data looks like this:

Excel 2012
AB
1NameScore
2Ciara2
3Emma4
4John1
5Total7
6James3
7Steve3
8Sarah2
9Total8

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Hoja1



You can use this to sort it in groups * AS LONG AS ALL TEAMS HAVE 3 MEMBERS*

Code:
Sub [COLOR=#574123]gymjohn[/COLOR]()
Dim lRow, i As Long


lRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
    
For i = 2 To lRow Step 4


    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range(Cells(i, 2), Cells(i + 2, 2)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range(Cells(i, 2), Cells(i + 2, 2))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Next


End Sub

You should get this result

Excel 2012
AB
1NameScore
2Ciara4
3Emma2
4John1
5Total7
6James3
7Steve3
8Sarah2
9Total8

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Hoja1
 
Upvote 0
I just noticed I made a mistake

If you have this:

Excel 2012
AB
1NameScore
2Emma2
3Ciara4
4John1
5Total7
6James3
7Steve3
8Sarah2
9Total8

<tbody>
</tbody>
Hoja1 (3)



Use this * AS LONG AS ALL TEAMS HAVE 3 MEMBERS*:

Code:
Sub Macro1()


Dim lrow, i As Long


lrow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
    
For i = 2 To lrow Step 4


    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range(Cells(i, 2), Cells(i + 2, 2)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range(Cells(i, 1), Cells(i + 2, 2))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Next


End Sub

To get this:

Excel 2012
AB
1NameScore
2Ciara4
3Emma2
4John1
5Total7
6James3
7Steve3
8Sarah2
9Total8

<tbody>
</tbody>
Hoja1 (3)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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