Quick Question on Calc to Long Var

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Quick Question on Calc to Long Var

Post by Rudi »

What am I missing??
It keeps on saying Object Required?

Code: Select all

Dim lgrp As Long 
    lgrp = WorksheetFunction.SumProduct(1 / WorksheetFunction.CountIf(rData.Columns(1).Address, rData.Columns(1).Address))
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78502
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Quick Question on Calc to Long Var

Post by HansV »

The first argument to CountIf should be a range, not an address. The second argument should be a value to compare the range to.
In a worksheet function saved as an array function, you can supply a range as second argument. This won't work in VBA however - you can't evaluate array formulas using WorksheetFunction.
As an alternative, you can use Evaluate:

Code: Select all

    lgrp = Evaluate("=SUMPRODUCT(1/COUNTIF(" & rData.Columns(1).Address & "," & rData.Columns(1).Address & "))")
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Quick Question on Calc to Long Var

Post by Rudi »

TX...That is working well now.
Again this Evaluate Function. I learn it...then never use it...then forget about it...until I need it...and then I dunno how to use it again...
Life is so unfair sometimes!!

TX Hans.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.