问题
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