CountIf和xlCellTypeVisible产生1004错误

我试图计算包含单词“更改”的字段数,但是这是在一个过滤列表上执行的,所以我使用SpecialCells(xlCellTypeVisible)属性来testing它们是否是过滤列表的一部分。 示例代码如下所示:

aWorkbook.Worksheets("Sheet1").Cells(22, 10).Formula = WorksheetFunction.CountIf(Range(Cells(3, 10), Cells(20, 10)).SpecialCells(xlCellTypeVisible), "Change") 

但我收到以下错误:

 Run-time error'1004': Unable to get the CountIf property of the WorksheetFunction class 

下面的代码,使用总和,按预期工作,但我觉得很奇怪

 aWorkbook.Worksheets("Sheet1").Cells(22, 7).Formula = WorksheetFunction.Sum(Range(Cells(3, 7), Cells(20, 7)).SpecialCells(xlCellTypeVisible)) 

 Public Sub CountValue() Dim rngValues as Range Dim varCounter as Variant Dim counter as Byte Set rngvalues = ThisWorkbook.Sheets("Sheet1").Range("$J$3:$J$20") For Each varCounter in rngvalues.SpecialCells(xlCellTypeVisible) If varCounter = "Change" Then counter = counter + 1 End if Next ThisWorkbook.Sheets("1").Range("$J$22").Value = counter End Sub