How to use OR Operator with SumIfs() [duplicate]

核能气质少年 提交于 2019-12-31 07:31:16

问题


How do I use SumIfs to sum if 1 out of 3 criteria (=OR) matches?

How can I use OR for the criteria? Here is the pseudocode.

Sub SumDemo()

    Dim Sum

    Sum = Application.WorksheetFunction.SumIfs([REVENUE], [UNIT], "=avengers", [region], "=north OR =south OR = west")

    MsgBox Sum

End Sub

回答1:


Try googling “VBA excel sumifs Or” and you will find result #1:

VBA - SumIfs with Or

Dim Sum as Double
Dim Revenue As Range, Unit As Range, Region As Range

'You will need to define your ranges.
Set Revenue = Range("")
Set Unit ...
Set Region ...

Sum = Application.Sum(Application.SumIfs(Revenue, Regions, Unit, "Avengers", Array("North", "south","west")))



回答2:


Slightly different approach than the duplicate, Use Evaluate to evaluate the worksheet formula.

Dim Sm As Long

Sm = ActiveSheet.Evaluate("Sum(SumIfs(REVENUE, UNIT, ""avengers"", region, {""north"", ""south"", ""west""}))")

MsgBox Sm


来源:https://stackoverflow.com/questions/47982724/how-to-use-or-operator-with-sumifs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!