function "sumproduct" in VBA environment

A

aw

Dear Sir / Madam,

Could anyone can help to translate the worksheet function – “sumproduct†(as
below) into VBA??


=SUMPRODUCT(--(yard="BSHKY"),--(ac_name="Yard Trucks"),amt)

Remark : “Yardâ€, “ac_name†& “amt†are pre-defined range.


My working as follow : (but run-time error ‘13’ type mismatch appear)

Sub sp()
a = InputBox("Yard")
b = InputBox("A/C name")
MyAns = Application.WorksheetFunction.SumProduct((Range("yard") = "a"),
(Range("ac_name") = "b"), Range("amt"))
End Sub

!!!Thank you so much!!!

Best rgds // aw
 
P

papou

Hello
If your sumproduct formula works, use Evaluate:
MyAns = Evaluate("=SUMPRODUCT(--(yard="BSHKY"),--(ac_name="Yard
Trucks"),amt)")

HTH
Cordially
Pascal
 
P

papou

Oops sorry, no equal sign needed:
MyAns = Evaluate("SUMPRODUCT(--(yard="BSHKY"),--(ac_name="Yard
Trucks"),amt)")

HTH
Cordially
Pascal
 

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

VBA Type Mismatch 7
sumproduct in vba 3

Top