Ok, here we go....
First, In the results sheet, I suggest you create a combo-box with Buyer and Vendor as the choices and link it to a cell, say B1 (so making a choice will result in a 1 or 2 in cell B1)...Or you can have the user enter a 1 for Buyer and 2 for Vendor directly in cell B1. Then have the user enter the value (actual Buyer or Vendor, in B2).
Then add this formula in the column header next to the PO header, =IF($B$1=1,"Vendor","Buyer") - in my example in Cell D1 of the results sheet. This is so the appropriate header is brought up based on your choice in A1.
Now in the 2nd row under PO header (cell C2, here), enter this formula,
=CHOOSE($B$1,IF(ROW($B2)-ROW($B$1)>COUNTIF(Sheet2!$B$1:$B$15,$B$2),"",INDEX(Sheet2!$A$1:$A$15,SMALL(IF(Sheet2!$B$1:$B$15=$B$2,ROW(Sheet2!$A$1:$A$15)),ROW($B2)-ROW($B$1)))),IF(ROW($B2)-ROW($B$1)>COUNTIF(Sheet2!$C$1:$C$15,$B$2),"",INDEX(Sheet2!$A$1:$A$15,SMALL(IF(Sheet2!$C$1:$C$15=$B$2,ROW(Sheet2!$A$1:$A$15)),ROW($B2)-ROW($B$1)))))
always adjusting ranges to suit. Then confirm with Ctrl+Shift+Enter.
In D2, enter this formula, =CHOOSE($B$1,IF(ROW($B2)-ROW($B$1)>COUNTIF(Sheet2!$B$1:$B$15,$B$2),"",INDEX(Sheet2!$C$1:$C$15,SMALL(IF(Sheet2!$B$1:$B$15=$B$2,ROW(Sheet2!$C$1:$C$15)),ROW($B2)-ROW($B$1)))),IF(ROW($B2)-ROW($B$1)>COUNTIF(Sheet2!$C$1:$C$15,$B$2),"",INDEX(Sheet2!$B$1:$B$15,SMALL(IF(Sheet2!$C$1:$C$15=$B$2,ROW(Sheet2!$B$1:$B$15)),ROW($B2)-ROW($B$1)))))
with the same adjustments and confirmations.
Be careful that the column letters correspond with your database sheet.
Then just copy down these formulas as far as you need.
Example Database Sheet (Sheet2)
TestDec15.xls |
---|
|
---|
| A | B | C | D |
---|
1 | PO | Buyer | Vendor | |
---|
2 | PO12 | Joe | 7 | |
---|
3 | PO23 | Jack | 11 | |
---|
4 | P034 | Mary | 9 | |
---|
5 | PO35 | Luke | 6 | |
---|
6 | PO36 | Chris | 6 | |
---|
7 | PO37 | Jack | 10 | |
---|
8 | PO38 | Chris | 11 | |
---|
9 | PO39 | Mary | 2 | |
---|
|
---|
Example Results Sheet with Buyer chosen:
Example Results Sheet with Vendor Chosen:
I really hope this helps!