VBA - 具有多个条件的 SumIf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42907357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA - SumIf with multiple criteria
提问by Robby
I'm having trouble figuring out how to set multiple criteria for a SumIf statement in VBA. This is what I'm using right now with only one criterion to set the value of a variable called Count_1.
我无法弄清楚如何在 VBA 中为 SumIf 语句设置多个条件。这就是我现在使用的只有一个标准来设置名为 Count_1 的变量的值。
Count_1 = Application.SumIf(Range("K84:K" & LastRow), "B*", Range("G84:G" & LastRow))
I need to add another criterion. In addition to the value in column K needing to begin with "B", the value in column L also needs to be 80.
我需要添加另一个标准。除了K列的值需要以“B”开头外,L列的值也需要是80。
I know this can be done using SumIfs in an Excel formula, but I need it to be in VBA.
我知道这可以在 Excel 公式中使用 SumIfs 来完成,但我需要它在 VBA 中。
回答by Pspl
Use
用
Application.Sumifs(SumRange, CriteriaRange1, Criteria1, CriteriaRange2, Criteria2,...)