Given a row in Excel with variable number of columns populated with item numbers, I'd like to do a lookup in another table listing the cost for each item in the populated columns, and sum the total cost. My Google-fu has failed me as I can't seem to find any way to perform an Excel formula (VLOOKUP in this case) on every cell in a range. Basically, if I have the following tables:
ItemCosts
Item | Cost
A | 10
B | 20
C | 40
Orders
Order |
1 | A
2 | A | B
3 | B | C
How can I calculate the total in the following table given an order number?
Order Summary
Order | Total
1 | 10
2 | 30
3 | 60
I've managed to write some formulas that generate the lookup range in the form Orders!$B$2:$C$2
. I thought I could use that range as the input to some formula to map the items in the order to their item costs and sum them. I had hoped I could perform a VLOOKUP on every item in the range and it could return a range from the ItemCosts
table that I could then sum but VLOOKUP only takes a single cell as the lookup value. I feel like I'm missing something obvious. Should I just do it in VBA? This answer mentions that VLOOKUP can take an array and then return an array but I couldn't reproduce it in Excel 2016 for Mac. It just returns the first match as a single value.
EDIT: Based on the comments it seems like the unnormalized Orders table might be a problem. But even if it looks like this, it's not clear to me how to perform a lookup of each item's cost so I can calculate the total.
Orders
Order | Item
1 | A
2 | A
2 | B
3 | B
3 | C