Question : Sumproduct in VB

Hi...

I understand the sumproduct well enough and i know how to apply it...But my problem is..if i apply the same formula in VB it gives me an error...What i want to understand how do you apply sumproduct in VB through application.worksheetfunction...here is a sample of what i'm doing...which gives me an error number 13 on sum product...

I even went through Brad's Solution out here...

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_20896095.html

And i understand that i cant use * in Sumproduct, but even if i use , it gives me the same error.. which i dont understand...

Want to understand this thing as it's gonna help me quite a lot..

Thanks for looking and replying over on this...

Saurabh...

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Sub s()
Dim a As Range
Dim b As Range
Dim c As Long
 
Set a = Sheets("Sheet1").Range("A2:A" & Cells(65536, "A").End(xlUp).Row)
Set b = Sheets("Sheet1").Range("B2:B" & Cells(65536, "A").End(xlUp).Row)
Sheets("Sheet2").Select
Range("A2").Select
c = 2
Do Until c > Cells(65536, "a").End(xlUp).Row
If (Application.WorksheetFunction.SumProduct(r = "Yes" * s = ActiveCell.Value) >= 1) Then
Rows(c).Delete
Range("A" & c).Select
Else
ActiveCell.Offset(1, 0).Select
c = c + 1
End If
Loop
End Sub

Answer : Sumproduct in VB

Since using the Evaluate function allows a string to be passed that looks just like the syntax in a worksheet formula, all you have to do is build it as you would any formula string:

   MsgBox Application.Evaluate("SUMPRODUCT((sheet1!A2:A" & EndRow & "=""Yes"")*(sheet1!B2:B" & EndRow & "=sheet2!A1))")

Kevin
Random Solutions  
 
programming4us programming4us