How to use Sumproduct in VBA???

  • Thread starter Thread starter FARAZ QURESHI
  • Start date Start date
F

FARAZ QURESHI

Hi friends,

I wanna know what's the problem with:

Public Function FHWA(One, Two)
FHWA=Application.Caller.Parent.Evaluate( _
"SUMPRODUCT("&One.Address&","&Two.Address&")")
End Function

The code gives a:
Compile Error
Expected: list separator or )

What would be the appropriate way to write a simple code for sumproduct of
two arrays named One & Two?

Thanx
 
Hi

Make sure you separate your concatenation operator (&) from the
variable names - the following works for me:

Public Function FHWA(One, Two)
FHWA = Application.Caller.Parent.Evaluate( _
"SUMPRODUCT(" & One.Address & "," & Two.Address & ")")
End Function

Hope this helps!

Richard
 
You might want some error handling

Public Function FHWA(One, Two)
If One.Cells.Count <> Two.Cells.Count Then
FHWA = "# mismatched ranges"
Else
FHWA = Application.Caller.Parent.Evaluate( _
"SUMPRODUCT(" & One.Address & "," & Two.Address & ")")
End If
End Function




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

Hi

Make sure you separate your concatenation operator (&) from the
variable names - the following works for me:

Public Function FHWA(One, Two)
FHWA = Application.Caller.Parent.Evaluate( _
"SUMPRODUCT(" & One.Address & "," & Two.Address & ")")
End Function

Hope this helps!

Richard
 
Thanx Richard,

It was your example that clarified to me now that there should be a space
existing between the concatenating symbol and rest.

In other words:

"SUMPRODUCT(" & One.Address & "," & Two.Address & ")") IS CORRECT
"SUMPRODUCT("&One.Address&","&Two.Address&")") IS WRONG

Thanx again!
 

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

Back
Top