简体   繁体   中英

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

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

I'm wondering if it is possible to format an array like this in 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.

Any help is appreciated!

answer to Q1 is yes, you can definitely build an array of string values in 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? you could just combine a loop with some ifs to solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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