Please help. Try as I might, I cannot find a simple formula which will sum all the cells in a row which are marked "A". The next cell has to tally all the cells marked "B".

I thought this would work but it didn't:

=SUM(B2:B40="A")