I am trying to use a CountIf function in vba on visible cells to count all the visible cells that are yes, there are 25 but I get the error
Unable to get the
CountIfproperty of theWorksheetFunctionclass
and it highlights returnCount, not sure if there is also an error with myrange, any help would be much appreciated.
Set myrange = _
Range("D4",Range("D4").End(xlDown)).SpecialCells(xlCellTypeVisible)
returnCount = WorksheetFunction.CountIf(myrange, "yes")
COUNTIF does not like non contiguous or multi-range ranges. So iterate the areas in the range
Dim myrange As Range
Dim ar As Range
Set myrange = _
Range("D4", Range("D4").End(xlDown)).SpecialCells(xlCellTypeVisible)
For Each ar In myrange.Areas
returncount = returncount + Application.WorksheetFunction.CountIf(ar, "yes")
Next ar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With