Look through 2 columns to return name from 3rd column

brutusmc99

Board Regular
Joined
Oct 6, 2014
Messages
111
Given the following table of NBA players who can play 2 different positions (a "-" indicates they only play 1 position:

Pos 1Pos 2Player
PG-Westbrook
PFCAldridge
CPFCousins
PFCLove
SFPFAnthony
SGSFHarden
PG-Lowry
CPFBosh
SFSGLeonard

<tbody>
</tbody>

I want to be able to look through both Position columns, Pos 1 & Pos 2, and output and sort the player names into a second table as follows:

PositionPlayer 1Player 2Player 3Player 4Player 5
PGWestbrookLowry
SGHardenLeonard
SFAnthonyHardenLeonard
PFAldridgeCousinsLoveAnthonyBosh
CAldridgeCousinsLoveBosh

<tbody>
</tbody>

So, the first player, Westbrook, is only a point guard, so he gets listed only under PG. But the second player, Aldridge, can play both power forward and center, so he is listed under both PF & C. And on down the list.

I can do it okay if I use only one position, i.e., Pos 2 (column B), using the following array formula:

{=INDEX($B$2:$C$11,SMALL(IF($B$2:$B$11=$S2,ROW($B$2:$B$11)-1),COLUMNS($T2:T2)),2)}

But, how can I use both positions (columns A and B)? Am I on the right track or do I need a new approach? Any help would be appreciated, thanks a lot.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You're probably not looking for a vba option, but just in case it will help or for future finders of this thread:

This assumes table 1 is on sheet1, beginning in A1.
This assumes table 2 is on sheet2, and merely includes the column/row headers in row 1 and column A

Code:
Sub moveNameTwoColumns()

    Dim nextCol As Long


    Dim list As Worksheet
    Dim table As Worksheet
    
    Set list = Sheets(1)
    Set table = Sheets(2)


    For x = 2 To table.Cells(Rows.Count, "A").End(xlUp).Row
        nextCol = 2
    
        For y = 2 To list.Cells(Rows.Count, "A").End(xlUp).Row
            If list.Cells(y, 1) = table.Cells(x, 1) Or _
                list.Cells(y, 2) = table.Cells(x, 1) Then
                
                    table.Cells(x, nextCol).Value = list.Cells(y, 3)
                    nextCol = nextCol + 1
                
            End If
        Next y
    Next x


End Sub
 
Upvote 0
Hi.

In T2, assuming you're using Excel 2007 or later, array formula**

=IFERROR(INDIRECT(TEXT(SMALL(IF($A$2:$B$10=$S2,10^5*ROW($A$2:$B$10)+COLUMNS($A$2:$C$10)),COLUMNS($A:A)),"R0C00000"),0),"")

Copy across and down as required.

Regards
 
Upvote 0
Hi.

In T2, assuming you're using Excel 2007 or later, array formula**

=IFERROR(INDIRECT(TEXT(SMALL(IF($A$2:$B$10=$S2,10^5*ROW($A$2:$B$10)+COLUMNS($A$2:$C$10)),COLUMNS($A:A)),"R0C00000"),0),"")

Copy across and down as required.

Regards


Works, perfectly. Thanks so much.
 
Upvote 0
You're probably not looking for a vba option, but just in case it will help or for future finders of this thread:

This assumes table 1 is on sheet1, beginning in A1.
This assumes table 2 is on sheet2, and merely includes the column/row headers in row 1 and column A

Thanks for the reply. Yeah, a vba approach is way above my pay grade:) Appreciate the effort, though. Hopefully, someone else will make good use of it.
 
Upvote 0
Or, maybe...

T2, confirmed with CONTROL+SHIFT+ENTER, copied across and down:

=IFERROR(INDEX($C$2:$C$10,SMALL(IF(($A$2:$A$10=$S2)+($B$2:$B$10=$S2),ROW($C$2:$C$10)-ROW($C$2)+1),COLUMNS($T2:T2))),"")

Hope this helps!
 
Upvote 0
Or, maybe...

T2, confirmed with CONTROL+SHIFT+ENTER, copied across and down:

=IFERROR(INDEX($C$2:$C$10,SMALL(IF(($A$2:$A$10=$S2)+($B$2:$B$10=$S2),ROW($C$2:$C$10)-ROW($C$2)+1),COLUMNS($T2:T2))),"")

Hope this helps!


Yeah, it works, too. Thanks a lot!
 
Upvote 0

Forum statistics

Threads
1,215,452
Messages
6,124,916
Members
449,195
Latest member
Stevenciu

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