The COUNTIFS function is a popular function if you want to count values for multiple conditions. It can also be used with VBA.
First, let’s take a look at how it works inside a worksheet.

The application counts numbers that are larger than 5, and smaller than 8.
In our example, there are three such numbers in cells: A1, C1, and G1.
VBA COUNTIFS
You can create a procedure in VBA that will look like this:
1 2 3 4 |
Sub myCountifs() BatchCount = Application.WorksheetFunction.CountIfs(Range("A1:G1"), ">5", Range("A1:G1"), "<8") MsgBox BatchCount End Sub |
If you run this code, it’s going to return the following message.
