Order values, return adjacent cell value

ATSJ

Board Regular
Joined
Dec 7, 2010
Messages
58
I have the following table structure

A
B
C
Allan
12
21
Bob
15
9
Chris
17
15
Dave
22
7

<tbody>
</tbody>

And I would like to use a formula that orders the values in columns B and C and returns the corresponding value in column A, as below...
A
B
Dave
22
Allan
21
Chris
17
Bob
15
Chris
15
Allan
12
Bob
9
Dave
7

<tbody>
</tbody>

Currently I have code that would order the values in one column, say B and then return A - but not two columns of values.

Any help is appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Assuming that row 1 has headers, try:
Code:
Sub ATSJ()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row).Cut Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
    Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Sheets("Sheet1").Sort.SortFields.Clear
    Sheets("Sheet1").Sort.SortFields.Clear
    Sheets("Sheet1").Sort.SortFields.Add Key:=Range("B2:B" & LastRow), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With Sheets("Sheet1").Sort
        .SetRange Range("A1:C" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
A formula approach...

Allan1221Dave22
Bob159Allan21
Chris1715Chris17
Dave227Bob15
Chris15
Allan12
Bob9
Dave7

<tbody>
</tbody>

In E2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=IF($F2="","",INDEX($A$2:$A$5,SMALL(IF($B$2:$C$5=$F2,ROW($A$2:$A$5)-ROW($A$2)+1),
    COUNTIFS($F$2:F2,F2))))

In F2 just enter and copy down:
Rich (BB code):
=IF(ROWS($F$2:F2)>COUNT($B$2:$C$5),"",LARGE($B$2:$C$5,ROWS($F$2:F2)))
 
Upvote 0
Thanks for the help folks, I like a formula based solution better in this particular case but good to have an alternative that works.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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