In Excel, I'm writing a custom function in VBA that needs to take a criteria string and criteria range like the built-in SUMIF
function. Does Excel expose the functionality to test a criteria string anywhere in its API or do I have to write it myself?
In case it's relevant, I'm writing a "CountUniquesIf" formula, that counts the unique values in a range if they meet a criterion. This is what I have so far.
Function CountUniquesIf(CondRange As Range, Criteria As String, _
Range As Range) As Long
Static dict As New Scripting.Dictionary
Dim index As Long
index = 1
For Each Cell In Range.Cells
If CondRange(index).Value = Criteria And Cell.Value <> "" Then
dict(Cell.Value) = Empty
End If
index = index + 1
Next Cell
CountUniquesIf = dict.Count
dict.RemoveAll
End Function