Luke said:
I have a ranges named ClaimClients and ClaimStat and a
value named ClientNum.
[Sorry about the premature posting. Hit the wrong "button".]
Are those named Excel objects, or are they the names of VBA variables?
If they are VBA variables, what are their definitions and how are their
values assigned?
Presumably:
Dim ClaimClients as Range, ClaimStat as Range
Set ClaimClients = Range("a1:a10")
Set ClaimStat = Range("b1:b10")
If that is the case, then you should use ClaimClients.Address and
ClaimStat.Address in the Evaluate string. Failure to do so would cause a
Type Mismatch error.
But you might have other errors, which, at the very least, might cause the
Evaluate function to fail to deliver the intended result.
It is unclear what type ClientNum is and how its value was assigned.
Your code snippet treats the value of ClientNum as a string. But is that
truly your intent? Is that the type of values in the cells represented by
the range variable ClaimClients?
Also, at a minimum, you need "--" before each SUMPRODUCT parameter.
In summary, the following might be what you intended:
ActiveCell.Offset(0, 10).Value = ActiveSheet.Evaluate("SUMPRODUCT(--(" & _
ClaimClients & "=""" & ClientNum & """),--(" & ClaimStat & "=""O""))")
FYI, that can also be written:
ActiveCell.Offset(0, 10).Value = ActiveSheet.Evaluate("SUMPRODUCT((" & _
ClaimClients & "=""" & ClientNum & """)*(" & ClaimStat & "=""O""))")
However, if ClaimClients, ClaimStat and pehaps even ClientNum are named
Excel objects, you should write:
ActiveCell.Offset(0, 10).Value = ActiveSheet.Evaluate("SUMPRODUCT((" & _
"ClaimClients=ClientNum)*(ClaimStat=""O""))")
Or if ClientNum is a VBA variable:
ActiveCell.Offset(0, 10).Value = ActiveSheet.Evaluate("SUMPRODUCT((" & _
"ClaimClients=""" & ClientNum & """)*(ClaimStat=""O""))")
PS: You could write simply Evaluate instead of ActiveSheet.Evaluate.
If none of those comments help, please post more VBA context in your
response, and address the questions I raised above.
----- original message -----
Luke said:
I've looked through the various posts concerning this, but still can't
quite
get this to work. I have a ranges named ClaimClients and ClaimStat and a
value named ClientNum. I want to find the number of times the
ClaimClients
range has a value of ClientNum and the ClaimStat range has a value of "O".
Here is the code at present:
ActiveCell.Offset(0, 10).Value = ActiveSheet.Evaluate("SUMPRODUCT((" & _
ClaimClients & "=""" & ClientNum & """),(" & ClaimStat &
"=""O""))")
With all the various things I've tried to make this work, I always get
either a Type Mismatch error or a Syntax error.
.