Thread
:
COUNTIF criteria in VBA
View Single Post
#
2
Posted to microsoft.public.excel.programming
Ardus Petus
external usenet poster
Posts: 718
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
Reply With Quote
Ardus Petus
View Public Profile
Find all posts by Ardus Petus