View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Worksheet Function countif

Range is to be represented as Range("A1:A" & nrows). Try the below code


Set Myrange = Worksheets("Sheet1").Range("A1:A" & nrows)

'for an exact cell match
NumberOfSummaries = Application.WorksheetFunction.CountIf(Myrange, "SUMMARY:")

OR

'to count cells containing SUMMARY:
NumberOfSummaries = Application.WorksheetFunction.CountIf(Myrange,
"*SUMMARY:*")


If this post helps click Yes
---------------
Jacob Skaria


"Hydra" wrote:

Set Myrange = Worksheets("Sheet1").Range("a1, a" & nrows)
NumberOfSummaries = Application.WorksheetFunction.CountIf(Myrange,
"SUMMARY:")

this throws and error that says "Unable to get countif function of the
worksheet function class"

Any idea what I'm doing wrong?