Okie...
So, there are probably better ways to do it. But, I'd have 2 more columns (probably hidden).
So:
22 | p | =IF(B1="p", A1,0) | =IF(B1="n",A1,0)
33 | p | =IF(B2="p", A2,0) | =IF(B2="n",A2,0)
..
55 | n | =IF(B5="p", A5,0) | =IF(B5="n",A5,0)
..
Then, you can sum both rows independantly.....
Does this make sense?
I can send you an example if you want.