简体   繁体   中英

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. Now I want to apply a SUMIFS function on this array, however I keep getting an array returned rather than a single value. 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. 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.

The sum range are all Double type. The output array is a 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? And have you defined the size of the Outputarray first with Redim ?...have you tried wrapping the .Sumifs(.... with a .Sum ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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