View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default VBA Countif across sheets?

More appropriately, row/col counts are Type Long, as well as the return
from CountIf. Using Type Double suggests you expect a decimal value,but
only whole numbers are used/returned...


Public Function CountApples&()
Dim rngSearch As Range

Const dTopRow& = 4: Const dLastRow& = 10

Application.Volatile
With Sheets("Sheet1")
Set rngSearch = .Range(.Cells(dTopRow, 1), .Cells(dLastRow, 100))
End With
CountApples = WorksheetFunction.CountIf(rngSearch, "apple")
Set rngSearch = Nothing
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion