You could use the SUMIF formula =SUMIF(range,criteria,sum_range).
Assuming your range is A1:C4 then =SUMIF(A1:A4,"O7",B1:B4) would give you 1 and =SUMIF(A1:A4,"O7",C1:C4) would give you 0
where A1:A4 is the range of O7,O6,O6.....
"O7" is the criteria or the criteria could be a cell containing the value O7
and B1:B4 is the range of the values you want to sum