【问题标题】:Excel VBA SUMIF Run-time error '424': Object RequiredExcel VBA SUMIF 运行时错误“424”:需要对象
【发布时间】:2017-03-10 10:25:27
【问题描述】:

这会产生错误:运行时错误“424”:需要对象

Private Function Y_Mode() As Double
    Dim MaxGrad As Double
    MaxGrad = WorksheetFunction.Max(Graduation_Series)
    Y_Mode = WorksheetFunction.SumIf(Graduation_Series, MaxGrad, Y_Series)
End Function

这条线失败了:

Y_Mode = WorksheetFunction.SumIf(Graduation_Series, MaxGrad, Y_Series)

一切似乎都已正确定义和实例化,每个数组的元素都是 Variant/Double 类型

Watch : + :     Graduation_Series :  : Variant/Variant(0 to 14) : SU_Solution.Y_Mode
Watch :   :     MaxGrad : 474.281204765715 : Double : SU_Solution.Y_Mode    
Watch : + :     Y_Series :  : Variant/Variant(0 to 14) : SU_Solution.Y_Mode

我尝试将 MaxGrad 放入 Range 中,然后在 SUMIF 中引用 Range,但这也不起作用。

【问题讨论】:

  • 如何制作你的系列Ranges?
  • 似乎 SumIf 不适用于数组。这个公式在 Excel Online 中给了我错误=SUMIF({1,2},2,{3,4})
  • 该函数可能应该采用ByVal graduationSeries As Range, ByVal ySeries As Range 参数而不是使用一些全局 (?) 状态。
  • 感谢您的反馈。我将沿着 SUM(IF()) 数组公式路径而不是转换为数组到 Range。
  • SUM(IF()) 在 VBA 中也不起作用,所以我不得不自己“滚动”。

标签: vba excel sumifs


【解决方案1】:

您不能将 SUMIF 与数组一起使用。

您可以与 SUMIF() 工作表函数一起使用的条件是 仅限于文本、数字或范围,并且该函数无法使用 数组常量。

https://support.microsoft.com/en-us/help/275165/when-to-use-a-sum-if-array-formula

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多