2017-03-21 71 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)"))) 

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