Are these macros the best way to make custom sorts easily accessible?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
I have been working on a sheet to track the rankings of the 32 NFL teams over the current season. The minisheet below is a simplified version of that sheet.

There are three different ways that I want to sort the table:
  1. Rank (ascending)
  2. Conference (descending), Rank (ascending)
  3. Conference (descending), Division (descending), Rank (ascending)
I could not find a simple way to save a custom sort. It seems to me that after I set up a custom sort, Excel ought to offer me the option to save it, but no. 🤨😡🤬

The only options I could find were macros and custom lists. Custom lists looked wierd to me, so I choose macros. This is what I came up with. They seem to work.

Can anyone see any problems or a better way?

VBA Code:
'==================================================================
'     Sort #1 - Rank
'==================================================================
Sub SortByRank()
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("TblNFL[Rank]"), Order:=xlAscending
'        .SetRange Range("TblNFL")  'This caused problems
        .SetRange ActiveSheet.ListObjects("TblNFL").Range
        .Header = xlYes
        .Apply
    End With
End Sub


'==================================================================
'     Sort #2 - Conference, Rank
'==================================================================
Sub SortByConferenceRank()
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("TblNFL[Conference]"), Order:=xlDescending
        .SortFields.Add Key:=Range("TblNFL[Rank]"), Order:=xlAscending
'        .SetRange Range("TblNFL")  'This caused problems
        .SetRange ActiveSheet.ListObjects("TblNFL").Range
        .Header = xlYes
        .Apply
    End With
End Sub


'==================================================================
'     Sort #3 - Conferene, Division, Rank
'==================================================================
Sub SortByConferenceDivisionRank()
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("TblNFL[Conference]"), Order:=xlDescending
        .SortFields.Add Key:=Range("TblNFL[Division]"), Order:=xlDescending
        .SortFields.Add Key:=Range("TblNFL[Rank]"), Order:=xlAscending
'        .SetRange Range("TblNFL")  'This caused problems
        .SetRange ActiveSheet.ListObjects("TblNFL").Range
        .Header = xlYes
        .Apply
    End With
End Sub

Sorting.xlsm
BCDEFGHI
2RankTeamConferenceDivisionWk 11 Average RankWk 10-11 Average ΔWk 11 RecordWk 10 Average Rank
310San Francisco 49ersNFCWest9.8↑0.25-410.0
413Arizona CardinalsNFCWest12.2↑3.36-415.5
518Los Angeles RamsNFCWest17.7↓3.74-514.0
619Seattle SeahawksNFCWest18.8↓1.84-517.0
714Altanta FalconsNFCSouth14.3↓2.86-411.5
816Tampa Bay BuccaneersNFCSouth16.8↑1.24-618.0
924New Orleans SaintsNFCSouth25.8↑2.73-728.5
1028Carolina PanthersNFCSouth27.3↑2.73-730.0
111Detroit LionsNFCNorth1.6↓0.68-11.0
127Minnesota VikingsNFCNorth7.8↓0.37-27.5
138Green Bay PackersNFCNorth8.1↓1.66-36.5
1421Chicago BearsNFCNorth21.0↓3.54-517.5
155Philadelphia EaglesNFCEast5.6↑0.97-26.5
169Washington CommandersNFCEast8.7↓0.77-38.0
1725Dallas CowboysNFCEast25.8↓3.33-622.5
1832New York GiantsNFCEast30.2↓4.22-826.0
192Kansas City ChiefsAFCWest1.8↑1.29-03.0
2011Los Angeles ChargersAFCWest11.6↑1.46-313.0
2117Denver BroncosAFCWest17.5↑1.55-519.0
2231Las Vegas RaidersAFCWest29.5↑2.02-731.5
2312Houston TexansAFCSouth11.7↓2.76-49.0
2422Indianapolis ColtsAFCSouth21.2↓0.24-621.0
2529Tennessee TitansAFCSouth28.8↓0.32-728.5
2630Jacksonville JaguarsAFCSouth28.8↓2.32-826.5
274Baltimore RavensAFCNorth3.7↓0.27-33.5
286Pittsburgh SteelersAFCNorth6.9↑4.17-211.0
2915Cincinnati BengalsAFCNorth15.6↑2.44-618.0
3027Cleveland BrownsAFCNorth26.8↑1.22-728.0
313Buffalo BillsAFCEast3.2↓0.78-22.5
3220Miami DolphinsAFCEast19.6↑4.43-624.0
3323New York JetsAFCEast22.9↓2.43-720.5
3426New England PatriotsAFCEast26.7↑2.33-729.0
2024 Power rankings
Cell Formulas
RangeFormula
B3:B34B3=RANK.EQ([@[Wk 11 Average Rank]],[Wk 11 Average Rank],1)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If you save it in OneDrive or SharePoint, you can create custom filters and save them by name.


 
Upvote 0
If you save it in OneDrive or SharePoint, you can create custom filters and save them by name.


Thanks. I'll study that.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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