Give this a go...it seems to work on my test sheet. Be sure to adjust the ranges to suit your situation. Again, this is an array formula and needs to be confirmed with Ctrl+Shift+Enter:
=INDEX(C2:C7,MATCH(MIN(ABS((B2:B7=F4)*A2:A7-F5)),ABS((B2:B7=F4)*A2:A7-F5),0),0)
It works by zeroing out keys that don't match your group assignment (that's the (B2:B7=F4)*A2:A7-F5) part. So only keys w/ valid groups have some number to be used to match to the data column.
Hope that helps explain it. You can also utilize the "Evaluate Formula" function on the Formulas toolbar to see it in action.
Note - it seems to return the 1st data value if 0 is used as the closest value (regardless of group selection). Not sure how to get around that...