If you are using Excel 2007, the try using the SUMIFS functions.

If using a prior version, use the IF function.

Why don't you edit your profile so that we know which version you are using?