Here is a minimal version of a SumIfs function
Function MySumIfs(sumrange As Range, ParamArray criteriapairs()) As Double
Dim n As Long
Dim index As Long
Dim bMatch As Boolean
' loop through sum range
For index = 1 To sumrange.Cells.Count
bMatch = True
' loop through criteria pairs (range and criteria to test for)
For n = LBound(criteriapairs) To UBound(criteriapairs) Step 2
' if doesn't match, set variable to false and skip the rest of the checks
If criteriapairs(n).Cells(index) <> criteriapairs(n + 1) Then
bMatch = False
Exit For
End If
Next n
' only add the value if all criteria met
If bMatch Then MySumIfs = MySumIfs + sumrange.Cells(index)
Next index
End Function
which you can call with varying numbers of criteria, such as
=MySumIfs($C$1:$C$15,$A$1:$A$15,"Item1")
or
=MySumIfs($C$1:$C$15,$A$1:$A$15,"Item1",$B$1:$B$15,"test1")
like the worksheet function.
Bookmarks