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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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