VBA - SumIfs with Or

2020-02-16 05:21发布

I have researched this issue everywhere, and I can't find an answer to my particular situation.

Here's my SumIfs statement.

B_white = Application.SumIfs(Range("G84:G" & LastRow), Range("G84:G" & LastRow), "1", Range("K84:K" & LastRow), "B*", Range("L84:L" & LastRow), "2 (test)")

For the final criterion, it needs to look for "2 (test)" OR just "2" but I can't use "2*" because there will be cells with "22" and "28" in them.

How can I alter this SumIfs statement so that it looks for "2 (test)" or "2"?

2条回答
Animai°情兽
2楼-- · 2020-02-16 05:35
B_white = Application.Sum(Application.SumIfs(Range("G84:G" & LastRow), Range("G84:G" & LastRow), "1", Range("K84:K" & LastRow), "B*", Range("L84:L" & LastRow), Array("2 (test)", "2")))
查看更多
Ridiculous、
3楼-- · 2020-02-16 05:37

You can try Sumproduct with an array-version of SumIfs:

B_white = Application.SumProduct(Application.SumIfs(Range("G84:G" & LastRow), _
    Range("G84:G" & LastRow), "1", Range("K84:K" & LastRow), "B*", _
    Range("L84:L" & LastRow), Array("2", "2 (test)")))

'                             ^^^^^^^^^^^^^^^^^^^^^^
查看更多
登录 后发表回答