Values of non-contiguous cells

  • Thread starter Thread starter TJ
  • Start date Start date
T

TJ

Hi

I am looking for a function that that can be used to replace the COUNTIF
worksheet function, but works on non-contiguous cells. Can someone point me
in the right direction.

Thanks
Tony
 
Maybe something like this:

Public Function MyCountif(ParamArray v())
Dim tot As Long, c As Variant
Dim rng As Range
tot = 0
c = v(UBound(v))
For i = LBound(v) To UBound(v) - 1
Set rng = Nothing
On Error Resume Next
Set rng = v(i)
On Error GoTo 0
If Not rng Is Nothing Then
tot = tot + Application.CountIf(v(i), c)
End If
Next
MyCountif = tot
End Function

Make sure you put it in a general module

sample usage:
=mycountif(A2:A5,C2:C5,E2:E5,H2:H5,">"&I2)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top