Sumproduct instead of SumifS in VBA (application.sumproduct)

  • Thread starter Majken Bilslev-Jensen
  • Start date
M

Majken Bilslev-Jensen

Hi all,

I have a problem in VBA using application.sumproduct.
The following code does not work:

Application.SumProduct((Application.Index(holdings.Range("holdings"),
0, 1) = "ff") * (Application.Index(holdings.Range("holdings"), 0, 5) =
"gg") * Application.Index(holdings.Range("holdings"), 0, 3))

Can anyone help me? Thanks heaps!
 
A

AB

That applies to all the functions you use - also the .index
Did you make that change too?
As far as I know the only way to reference/use genuine Excel Worksheet
functions is via the:
application.worksheetfunction.
construct.
So, did you make that other change too?
 
J

Jim Rech

I don't think VBA can evaluate this "formula" like Excel itself can. It
breaks down pretty early in the process.

While it can do this:

Dim Arr As Variant
Arr = Application.Index(Range("Holdings"), 0, 1)

returning an array of the values in column 1 of Holdings, you would hope
that this:

Dim Arr As Variant
Arr = (Application.Index(Range("Holdings"), 0, 1) = "ff")

would return an array of True and False. But it errors. I think in VBA you
just have to address each element of the array individually.
 
A

AB

It appears that Jim is right - I'm also getting the type-mismatch
error.
Perhaps you can work around this by using some tempcell - put the
formula into a cell, get Excel to evalueate it, read the cells value
and then remove the formula from the cel...
Not an elegant solution but...
 
D

Don Guillett Excel MVP

It appears that Jim is right - I'm also getting the type-mismatch
error.
Perhaps you can work around this by using some tempcell - put the
formula into a cell, get Excel to evalueate it, read the cells value
and then remove the formula from the cel...
Not an elegant solution but...










- Show quoted text -

With sumproduct you must use application.EVALUATE("your formula")
 
J

joeu2004

The following code does not work:

Application.SumProduct((Application.Index(holdings.Range("holdings"),
0, 1) = "ff") * (Application.Index(holdings.Range("holdings"), 0, 5) =
"gg") * Application.Index(holdings.Range("holdings"), 0, 3))

Try this:

Evaluate("SUMPRODUCT((INDEX(Holdings,0,1)="ff")*(INDEX(Holdings,
0,5)="gg"),
INDEX(Holdings,0,3)")

Note: Enter the entire formula on __one__ VBA line or use apply VBA
line continuation syntax appropriately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

sumproduct in vba 3
SUMPRODUCT in VBA 3
mixing of vba and sumproduct 5
TRANSPOSE and INDEX limit in Excel2007 2
Empty Array 4
Barcode Scanner 1
Help with code please? 6
average of array element 11

Top