2017-03-21 75 views
0

我已经研究过这个问题到处都是,我无法找到我的特定情况的答案。VBA - SumIfs或

这是我的SumIfs语句。

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

对于最终的标准,它需要寻找“2(测试)”或只是“2”,但我不能用“2 *”,因为将有以“22”细胞“28 “ 在他们中。

我该如何修改这个SumIfs语句,以便它查找“2(test)”或“2”?

+0

'SUM(SUMIFS(......,......,......, {“2”,“2(test)”}))''SUMIFS'没有内置的OR支持,只需传递一个数组中的条件并求和它们的结果。 – cyboashu

+0

对不起。我不知道如何将其纳入声明。 – Robby

+0

@cyboashu'{'不是vba中的有效字符。 –

回答

2
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"))) 
2

你可以尝试Sumproduct阵列版本的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)"))) 

'        ^^^^^^^^^^^^^^^^^^^^^^