Have you looked at the Excel function "Sumproduct"?