hi lo
hi lo

Reputation: 67

method 'range' of object '_global' failed vba access

problem with correct statement

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

i want to select an entire column minus a cell in VBA. how can I do this?

Upvotes: 0

Views: 80

Answers (1)

EylM
EylM

Reputation: 6103

You can write a helper function for this:

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

Usage:

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

Upvotes: 1

Related Questions