对象'_global'的方法'范围'失败VBA访问

时间:2019-08-24 08:15:06

标签: excel vba range

陈述正确的问题

Application.WorksheetFunction.CountIf(Range("B:B-B5"), a) 

我想选择减去VBA中整个单元格的整个列。 我该怎么办?

1 个答案:

答案 0 :(得分:1)

您可以为此编写一个辅助函数:

Function CountIfExcept(from As range, except As range, criteria As String)
    CountIfExcept = Application.WorksheetFunction.CountIf(from, criteria) - Application.WorksheetFunction.CountIf(except, criteria)
End Function

用法:

totalCount = CountIfExcept(Range("B:B"), RANGE("B5"), "some condition")