VBA 使用具有更多条件的 SUMIFS
VBA using SUMIFS with more criteria
我在 VBA 中使用 SUMIFS 时遇到问题。问题是我需要使用 SUMIFS 对数据集中的 1 个以上的城市求和。
我已经尝试 google 并使用 Whosebug 并找到了 2 个我都尝试过的答案,但其中 none 有效。其中之一是:
Dim D As Double
D = WorksheetFunction.Sum(WorksheetFunction.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
MsgBox D
我期待一个数值结果,但我得到了结果 "Run-time error '13': Type mismatch"
这些需要后期绑定所以使用 Application.
而不是 WorksheetFormula
:
根据:
The result should be captured into a Variant to prevent a type mismatch upon assignment of D if any of the values involved is a worksheet error.
Dim D As Variant
D = Application.Sum(Application.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
If IsNumeric(D) Then MsgBox D
我在 VBA 中使用 SUMIFS 时遇到问题。问题是我需要使用 SUMIFS 对数据集中的 1 个以上的城市求和。
我已经尝试 google 并使用 Whosebug 并找到了 2 个我都尝试过的答案,但其中 none 有效。其中之一是:
Dim D As Double
D = WorksheetFunction.Sum(WorksheetFunction.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
MsgBox D
我期待一个数值结果,但我得到了结果 "Run-time error '13': Type mismatch"
这些需要后期绑定所以使用 Application.
而不是 WorksheetFormula
:
根据
The result should be captured into a Variant to prevent a type mismatch upon assignment of D if any of the values involved is a worksheet error.
Dim D As Variant
D = Application.Sum(Application.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
If IsNumeric(D) Then MsgBox D