If you're using VBA, you don't need to restrict yourself to CountIfs
limited abilities, you can loop through every row and count up the values with your own custom script. Get the last row of the sheet with this technique and then you can loop through the sheet like:
Sub Example()
Dim SearchValue1 As String, SearchValue2 As String, SearchValue3 As String
SearchValue1 = "12345"
SearchValue2 = "Daniel"
SearchValue3 = "End"
Dim ws As Worksheet
Set ws = ActiveSheet
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Dim i As Long, SearchCount As Long
For i = 1 To LastRow
If ws.Cells(i, 1) = SearchValue1 _
And ws.Cells(i, 2) = SearchValue2 _
And ws.Cells(i, 3) = SearchValue3 _
Then
SearchCount = SearchCount + WorksheetFunction.CountIf(ws.Rows(i), "<>") - 3
End If
Next
Debug.Print SearchCount
End Sub
This could also be turned into a User Defined Function that accepts the SearchValues and the search range as arguments, and then returns the SearchCount
.
Move the code into a code module, and modify it like so:
Function CustomCount( _
SearchRange As Range, _
SearchValue1 As String, _
SearchValue2 As String, _
SearchValue3 As String _
)
Dim ws As Worksheet
Set ws = SearchRange.Parent
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Dim i As Long, SearchCount As Long
For i = 1 To LastRow
If SearchRange.Cells(i, 1) = SearchValue1 _
And SearchRange.Cells(i, 2) = SearchValue2 _
And SearchRange.Cells(i, 3) = SearchValue3 _
Then
SearchCount = SearchCount + WorksheetFunction.CountIf(ws.Rows(i), "<>") - 3
End If
Next
CustomCount = SearchCount
End Function
As a UDF you can use it inside your Excel formulas like =CustomCount(A:C,"12345","Daniel","End")
This UDF could be further improved by adjusting the code to allow a variable number of SearchValues. You could make some optional, or you could make them into a ParamArray. But I will not put that in this answer and leave that for you to explore if you are interested.