Pergunta

I am trying to avoid using VBA if that's at all possible and I most certainly think that it is!

I'm currently trying to sum up a range if a certain condition is met. My function works when the range is limited and small, but does not work when I encompass my actual desired range. Here is some snippets of code:

=SUMIF(B13:M13,P23, B15:M15)   

That function currently sums from B15 to M15 if there are any matches in between B13 and M13 with P23. It works like a charm. If there are discrepancies in between B13 and M13 it will only sum that matches which is exactly what I want it to do.

I want it to cover a much broader range, so I altered my formula as follows:

=SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53)

I want it to do the same thing as before. I want it to analyze B13:M13 as well as B32:M32 as well as B51:M51 and compare it to P23. If there are matches I want it to sum B15:M15 as well as B34:M34 as well as B53:M53. If there are non matches, I want them to be omitted as was the case in my previous function.

Can anyone tell me what's wrong with my formula?

Foi útil?

Solução

Actually, your formula =SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53) converts to =SUMIF(B13:M51,P23, B15:M53) (you can check it for example using "Evaluate formula" tool in the "Formulas" Ribbon or by entering in cell B18 value, euqals to P23, and another value in B20 - your formula will add value from B20 to the result). And it doesen't calculate propertly, because you have some text values in B16:M33, B35:M52

So, you can use following formula instead:

=SUMPRODUCT((B13:M13=P23)*(B15:M15)+(B32:M32=P23)*(B34:M34)+(B51:M51=P23)*(B53:M53))

Here is result of evaluating your formula (=SUMIF(B13:M13:B32:M32:B51:M51,P23, B15:M15:B34:M34:B53:M53)):

enter image description here


enter image description here


enter image description here


enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top