简体   繁体   English

VBA - 如何使用SUMIFS从数组返回单个值?

[英]VBA - How to return a single value from array using SUMIFS?

I'm trying to write up some code but am running into an unexpected issue and was hoping someone here could help. 我正在尝试编写一些代码,但遇到了一个意想不到的问题,并希望有人可以提供帮助。

Basically I have a set of data (about 150k rows) and have used VBA to read them into an array. 基本上我有一组数据(约150k行)并使用VBA将它们读入数组。 Now I want to apply a SUMIFS function on this array, however I keep getting an array returned rather than a single value. 现在我想在这个数组上应用一个SUMIFS函数,但是我继续得到一个返回的数组而不是一个值。 I'm using something along the lines of: 我正在使用以下内容:

With Application
    OutputArray(1, 1) = .SumIfs(.Index(MyArray, 0, 1), .Index(MyArray, 0, 2), ">0")
End With

Now, I can use a .Sum in this way and get a single value. 现在,我可以用这种方式使用.Sum并获得单个值。 When applying the exact same .SumIfs function as used in the VBA directly on the worksheet I also get a single value, but in the VBA code all I'm getting is an array of type Error. 当直接在工作表上应用与VBA中使用的完全相同的.SumIfs函数时,我也得到一个值,但在VBA代码中,我得到的是一个Error类型的数组。

The sum range are all Double type. 总和范围都是Double类型。 The output array is a Variant. 输出数组是Variant。

If I'm missing any additional information, please let me know. 如果我遗漏了任何其他信息,请告诉我。

Can you upload a sample of the data you are trying to apply the Sumifs to? 您可以上传试图将Sumifs应用到的数据样本吗? And have you defined the size of the Outputarray first with Redim ?...have you tried wrapping the .Sumifs(.... with a .Sum ? 你有没有用Redim定义Outputarray的大小?...你试过包装.Sumifs(....带有.Sum

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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