Using Sumproduct in VBA

George J

Well-known Member
Joined
Feb 15, 2002
Messages
959
I am struggling with this - i think my text string is correct and when copying it to a cell to test, works okay, but I get error 2015 in VBA. I can't use sumif as the numbers are entered as text on the workbook.

Code:
prop.Offset(0, 2).Value = Application.Evaluate("=SumProduct((" & _
      Range(myUsedRange.Offset(0, 3), myUsedRange.Offset(0, 5)).Address & "=" _
      & Chr(34) & prop.Value & Chr(34) & ")*(" & myUsedRange.Offset(0, 6).Address & "))")
This is the code I have which returns #value on the workbook. When entering the text to be evaluated as a formula however: =SumProduct(($D$2:$F$2083="my text")*($G$2:$G$2083))
It seems to work fine, so not sure why an error is coming up.

Can anyone point me in the right direction?
thanks.
 
It works fine after removing the £ symbols from the values being multiplied.
Even if those values remain as TEXT strings in the sheet.

OR, changing them to $, due to VBA being US centric.
 
Upvote 0
Oh I see. You hadn't mentioned that! ;)
 
Upvote 0
But you quoted my post explaining why the original file didn't work (and that it would work if you changed the code to substitute the £ signs)
The issue is that the formula version performs implicit coercion, but it doesn't do that within Evaluate.
and stated that Evaluate did work, even though the whole thread was about the fact it didn't.

Anyway, it's all moot now.
 
Upvote 0
I read that to mean that evaluate(sumproduct) doesn't do implicit coercion.
But it DOES.
Even the code you posted that subsituted the £ was still doing implicit coercion.

I wouldn't say it's a moot point, but maybe the discussion doesn't belong in this thread anymore.
 
Last edited:
Upvote 0
My point was simply that exactly the same formula worked in the cell, but failed in Evaluate because within Evaluate it was not coercing the £ values to numbers. Yes, it will coerce plain numbers stored as text but that was not the issue.
 
Upvote 0

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