Returns values based on one cell

nkroberts

New Member
Joined
Mar 5, 2015
Messages
18
On sheet 1 I have a drop down in cell A1 that lists 4 teams. On sheet 2 I have a list of athletes (column B) their team (Column A) and their score (Column C).

Depending on what is selected in cell A1 I want to list their top ten athletes (A2:A11) and their scores (B2:B11)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
alter the sheet names as you wish:

Code:
Sub TopSort()
Dim iRows As Long, iStart As Long, iLast As Long
Dim shtTarg As Worksheet
Dim sTeam


sTeam = Range("A1").Value


Sheets("Teams").Activate
    Range("A1").Select
    Cells.Find(What:=sTeam, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    iStart = ActiveCell.Row
    While ActiveCell.Value = sTeam
        ActiveCell.Offset(1, 0).Select
    Wend
    iLast = ActiveCell.Row - 1
    iRows = iLast - iStart + 1
    
    Range("A" & iStart & ":C" & iLast).Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    Set shtTarg = ActiveSheet
    
    ActiveSheet.Paste
    Application.CutCopyMode = False
    shtTarg.Sort.SortFields.Clear
    shtTarg.Sort.SortFields.Add Key:=Range("C1:C" & iRows), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With shtTarg.Sort
        .SetRange Range("A1:C" & iRows)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
    ActiveSheet.Name = sTeam
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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