Okay, so in Cell B1 I have the below formula (not an Array formula) which works perfectly in Excel:
SUMPRODUCT(1/COUNTIF(A1:A4,A1:A4))
This identifies unique values in a range of cells. So, if A1 = "A", A2 = "B", A3 = "B" and A4 = "C" the result of this formula is 3. Which is correct. However, if I try and replicate the exact same function in VBA as follows...:
Range("B1") = WorksheetFunction.SumProduct(1 / WorksheetFunction.CountIf(Range("A1:A4"), Range("A1:A4")))
I get a "Run-Time error '13': Type mismatch" error.
I've narrowed it down to the fact that VBA doesn't like that I'm using a multi-cell Range (ie A1:A4) as oppose to a single cell Range (ie A1) in my CountIf.
I've already written procedure to accommodate the end result that I'm looking for but it's not as elegant as it would be if I could just get the above to work. Can anyone enlighten me on what I might be doing wrong or is this simply not possible?
application.evaluate(...)if you properly referen ce the parent worksheets. - user4039065/though! Also, you can't useWorksheetfunction.Countiflike that - you have to useApplication.Countif- Rory