简体   繁体   English

Excel VBA中sum(sumifs())的条件数组

[英]Criteria array for sum(sumifs()) in Excel VBA

I know that the easiest way to incorporate "OR" logic into a sumifs situation in Excel is to nest 我知道将“ OR”逻辑合并到Excel中的sumifs情况中的最简单方法是嵌套

sum(sumifs(sumrange, criteria1range, {"crit11", "crit12", etc.}))

I'm wondering if it is possible to format an array like this in Excel VBA. 我想知道是否可以在Excel VBA中格式化这样的数组。 I'm currently trying to build the array based on the T/F conditions of 10 checkboxes, so rewriting the sum(sumifs()) for each variation isn't really an option. 我目前正在尝试根据10个复选框的T / F条件构建数组,因此为每个变sum(sumifs())并不是一个真正的选择。

Any help is appreciated! 任何帮助表示赞赏!

answer to Q1 is yes, you can definitely build an array of string values in VBA: 问题1的答案是肯定的,您绝对可以在VBA中构建字符串值数组:

Dim myarray() As String
myarray = Split("crit1,crit2,etc", ",")

Q2: I'm still looking into the format for using this in the worksheetfunction.sumifs as I find this to be an interesting approach but my question is if you're building this in VBA then why restrict yourself to using the worksheet functions? Q2:我仍然在工作表函数中查找使用此格式。sumifs,因为我发现这是一种有趣的方法,但是我的问题是,如果您要在VBA中构建它,那么为什么要限制自己使用工作表函数呢? you could just combine a loop with some ifs to solve your problem 您可以将循环与一些ifs结合起来以解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM