“无法获得Worksheetfunction类的Countif属性"错误 [英] "Unable to get the Countif property of the Worksheetfunction class" error

查看:153
本文介绍了“无法获得Worksheetfunction类的Countif属性"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码时出现无法获取Worksheetfunction类的Countif属性"错误

I get a "Unable to get the Countif property of the Worksheetfunction class" error when using this code

    Windows("usertemp.xls").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AO$18695").AutoFilter Field:=14, Criteria1:=Array( _
    "28", "BE", "CH", "DE", "FR", "JP", "NL"), Operator:=xlFilterValues
Dim Impats As Integer
Impats = Application.WorksheetFunction.CountIf(Range("AL:AL").SpecialCells(xlCellTypeVisible), "I")
MsgBox Impats

推荐答案

CounIf不接受多区域范围.您需要遍历Areas:

CounIf does not accept a multi-area range. You need to loop over the Areas:

Dim impats As Long, r As Range
For Each r In Range("AL:AL").SpecialCells(xlCellTypeVisible).Areas
    impats = impats + WorksheetFunction.CountIf(r, "I")
Next

这篇关于“无法获得Worksheetfunction类的Countif属性"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆