How do I create a formula to copy a value from a certain cell into a formula based on information from another cell(s).

For example if

A1=John A2=smith A3=value of interest1

B1=John B2=smith B3=value of interest2

A1=John A2=Jones A3=value of interest1

B1=John B2=Jones B3=value of interest2

I would like the formula to take the value from cell in column 3, depending on which john I am interested in, and say make an average.

Of course the problem is that although the related cells will always be adjacent to each other, the spreadsheet is varaible from time to time (for example John Smith may not be there at all, or represented only once, in which case the formula calculation is unncessary)

could the formula be something like

If A1 and A2 = B1 and B2 then average A3 and B3. But instead of using specific cell addresses, use a named range?

I hope this is even remotely clear!