sumproduct in VBA

G

Guest

I want to use the SUMPRODUCT function in my code. The function, as I would
write it in an Excel cell, is as follows.

=IF(SUMPRODUCT((series=Sheet1!$A2)*(status="Open"))=0,"Done","Pending Action")

Where "series" and "status" are ranges of cells (both single column, 10,000
rows) that have been named.

I've tried using the follow variations of VB code, but I keep getting a
run-time error '13' message: "Type mismatch."

Application.WorksheetFunction.SumProduct((Range("series") = Cells(1,
1).Value) * (Range("status") = "Open"))

Application.WorksheetFunction.SumProduct((Array("series") = Cells(1,
1).Value) * (Array("status") = "Open"))

I've stopped iterating through other possible variations to save myself time
and frustration. Does anyone know the correct arguments to get the desired
result? My aim is to look at a large tabular dataset, determine if the
"status" of any items corresponding to a specified identifier is "open", then
execute other code accordingly. So if sumproduct = 0 do x, else do y.
Thanks in advance for your help!
 
H

Harald Staff

Hi

I'd have my code enter the formula into a spare cell, calculate, read &
remember the result and delete the formula.

HTH. Best wishes Harald
 
B

Bob Phillips

Just evaluate it

myVal = Evaluate("=SUMPRODUCT((series=Sheet1!$A2)*(status=""Open""))")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
G

Guest

Works perfectly! Thanks.

Bob Phillips said:
Just evaluate it

myVal = Evaluate("=SUMPRODUCT((series=Sheet1!$A2)*(status=""Open""))")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
G

Guest

Thanks Harald. I was aware of that option, but looking for a way to do it in
code alone. Turns out, the evaluate function allows you to do what you were
suggesting, but in code alone:

myVal = Evaluate("=SUMPRODUCT((series=Sheet1!$A2)*(status=""Open""))")

Thanks again for your help.
 

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 VB 7
VBA Type Mismatch 7
function "sumproduct" in VBA environment 2
Using SUMPRODUCT in VBA 5
Sumproduct error 2
OFFSET and SUMPRODUCT 1
SumProduct in VBA 9
Type mismatch error using Sumproduct 7

Top