Sumproduct gives value error

fraufreda

Board Regular
Joined
Oct 14, 2010
Messages
190
Good day to you all
The sumproduct formula is working perfect but since ranges I set in the code are dynamic I am facing a problem to get it work. I tried to google for a solution but without success. I hope you can help. Here is part of the code
VBA Code:
Dim PyFields, Amounts, rng As Range
Dim ReportSht As Worksheet

Set ReportSht = Sheets("PR report")

With ReportSht
    Set PyFields = .Range(.Cells(2, 4), .Cells(2, LC))
    Set Amounts = .Range(.Cells(3, 4), .Cells(LR, LC))
End With

For each rng in Range(xxxx)
rng.Offset(0,1).Value = Application.Evaluate("SumProduct((" & PyFields.Address & " = """ & rng.Value & """)," & Amounts.Address & ")")
next
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
VBA Code:
Set PyFields = Application.InputBox("Select range.", "PyFields Range", Type:=8)
Set Amounts = Application.InputBox("Select range.", "Amounts Range", Type:=8)
 
Upvote 0
Maybe
VBA Code:
For Each rng In Range(xxxx)
rng.Offset(0, 1).Value = ReportSht.Evaluate("SumProduct(--(" & PyFields.Address & " = """ & rng.Value & """)," & Amounts.Address & ")")
Next
 
Upvote 0
VBA Code:
Set PyFields = Application.InputBox("Select range.", "PyFields Range", Type:=8)
Set Amounts = Application.InputBox("Select range.", "Amounts Range", Type:=8)
thank you but I don't want to select. I want the code to run without any user selection
 
Upvote 0
In that case can you post some sample data.
 
Upvote 0
Could you put your PyFields and Amounts data into a Table and refer to the Tables? That way the Range of the Table could be called using:
VBA Code:
Range(ActiveSheet.ListObjects("TableName")).Address

And Tables are dynamic.
 
Last edited:
Upvote 0
Got it. The problem was with the ranges that were set. Their addresses were not referenced to the sheet.
 
Upvote 0
I see three problems with the OP code:
1) Yes, in both the terms in SumProducts there was a "NameOfTheSheet!" missing
2) Yes, the "--" is missing
3) The two terms in SumProduct have different leght, as the first term is 1 Row * N column, whereas the second has (LR-3) Rows * N Columns

Anyway, glad that he found a working solution
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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