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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,515
Messages
6,125,279
Members
449,220
Latest member
Excel Master

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