You are looking for a Lookup with multiple criteria. A quick search gives several useful links, listed below. I have marked with * those that I have answered.
I have filtered out some of the links that actually deal with other issues.
As seen in the links, there are several options to achieve your goal. I personally prefer those that do not need array formulas, using an answer to question 1 with LOOKUP
or an answer to question 2 with SUMPRODUCT
.
Since you mentioned that you need a VBA solution, you can use WorksheetFunction
to use an Excel formula in VBA code, or check answers to question 7.
-
http://spreadsheets.about.com/b/2014/01/08/excel-lookup-formula-using-multiple-criteria.htm
-
http://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list
-
http://blogs.office.com/2012/04/26/using-multiple-criteria-in-excel-lookup-formulas/
PS: The (probably partial) list of (probably) duplicated questions provided above shows the usefulness of what was proposed in https://meta.stackexchange.com/questions/211366/group-duplicate-questions-for-convenience