SUMPRODUCT working in worksheet but not in VBA

eloirjr

New Member
Joined
Aug 27, 2010
Messages
25
I have this formula on sheet SUMPRODUCT(--(MONTH(Venda!$L$3:$L$5000)=MONTH($A9)); --(YEAR(Venda!$L$3:$L$5000)=YEAR($A9)); Venda!M3:M5000), it´s works fine but I have to translate to VBA code.
I have been tried
Sheets("Venda").Select
Range("A3").Select
Lastcl = Cells(Rows.Count, "A").End(xlUp).Row
TotParcPrev1 = Application.SumProduct(--Sheets("Venda").Range(Month("L3:L" & Lastcl)) = Month(tempdata), --Sheets("Venda").Range(Year("L3:L" & Lastcl)) = Year(tempdata), Sheets("Venda").Range("M3:M" & Lastcl)), but the total is empty. When I used evaluate, give the error 2015.
Maybe I´m making something wrong.
Thanks in advance
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
SUMPRODUCT in VBA is a little different - best to use an Evaluate approach:

Code:
Dim Lastcl As Long
Dim TotParcPrev1 As Double
With Sheets("Venda")
    Lastcl = .Cells(.Rows.Count,"A").End(xlUp).Row
    TotParcPrev1 = .Evaluate("SUMPRODUCT(--(TEXT(L3:L" & LastCl & ",""mmyyyy"")=TEXT(tempdata,""mmyyyy"")),M3:M" & LastCl & ")")
End With
 
Upvote 0
Little to add I'm afraid - the VBA replicates your existing approach
(uses tempdata per your VBA attempt rather than A9 as per your native formula - I assumed this was a named range [rather than a variable]).

If tempdata is blank and you have blank rows in L with values in M then you will generate a result - you may wish to adjust the formula logic accordingly
(ie pre-emptive IF or Number test against L)
 
Last edited:
Upvote 0
You´re right, I did the changes without sucess
With Sheets("Venda")
Lastcl = .Cells(.Rows.Count, "A").End(xlUp).Row
TotParcPrev1 = .Evaluate("SUMPRODUCT(--(TEXT(L3:L" & Lastcl & ",""mmyyyy"")=TEXT(A" & p + 8 & ",""mmyyyy""))*M3:M" & Lastcl & ")")
End With

Shows 0 yet
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top