Reputation: 1326
I have an Excel table, named myTable, the contents of which are shown below:
Partners 2-Jan 3-Feb 25-Mar 27-Mar
O2 20 23 26 0
Vodafone 1 23 25 29
Vectone 0 0 50 60
Orange 25 12 34 15
I have two more cells that contain the search criteria for
For example, cell A1 contains '3-Feb', and cell A2 contains 'Vectone'.
I would like to use these 2 cells to make a selection from myTable. For example, using '3-Feb' and 'Vectone' would return 0 from myTable.
Thanks.
Upvotes: 0
Views: 97
Reputation: 1326
Thanks to pnuts, whose answer I have adopted after slightly modifying it.
There were 2 problems faced in using cell contents as search criteria for myTable:
myTable would surely expand in future, with more dates and partners. If we renamed the column and row labels for myTable, and then added another partner and some dates, we would have to assign the names for these new partners and dates manually.
If I used the cell content of A1 directly, it resulted in an error. This is because the value in A1, 3-Feb, would be a date of a different format (2/3/2014) than that found in myTable (d-mmm). Hence, Match
was not successful in this case. I have made use of Text
function to convert the value in A1 to text in the required format, which resulted in a correct match.
The following is my answer adopted from @pnuts response.
=INDEX(myTable,MATCH(A2,myTable[Partners],0),MATCH(TEXT(A1,"d-mmm"),myTable[#Headers],0))
Here, myTable[Partners] refers to the column containing partner names, while myTable[#Headers] refers to the row containing dates.
The Text
function converts cell A1 to text, allowing Match
to function.
The following was my initial attempt, but for fear of slowing down Excel in future, when there would be lots of more partners and dates, I do not prefer it.
=VLOOKUP(A2,myTable,MATCH(TEXT(A1,"d-mmm"),myTable[#Headers],0),FALSE)
Upvotes: 0