View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ardus Petus Ardus Petus is offline
external usenet poster
 
Posts: 718
Default COUNTIF criteria in VBA

Public Function CountVIf(rng As Range, criteria As String) As Long
Dim cell As Range, cmd As String

For Each cell In rng
If cell.RowHeight < 0 And cell.ColumnWidth < 0 Then
cmd = "=" & cell.Address & criteria
If Evaluate(cmd) Then CountVIf = CountVIf + 1
End If
Next cell
End Function

HTH
--
AP

"whitehurst" a
écrit dans le message de news:
...

What vba function can I use that checks criteria much like SUMIF or
COUNTIF uses? In other words, say you want to write COUNTIF that only
includes visible cells...

Public Function CountVIf(rng As range, criteria As String)
Dim cell As range, cmd As String

For Each cell In rng
If cell.RowHeight < 0 And cell.ColumnWidth < 0 Then
cmd = "COUNTIF(" & cell.Address & ",""" & criteria & """)"
CountVIf = CountVIf + Evaluate(cmd)
End If
Next cell
End Function

How can I do this without having to rely on Evaluate("COUNTIF...."?

Thanks!


--
whitehurst
------------------------------------------------------------------------
whitehurst's Profile:
http://www.excelforum.com/member.php...o&userid=34544
View this thread: http://www.excelforum.com/showthread...hreadid=550351