I am trying to code an Excel UDF with a similar syntax to the builtin SUMIFS
, that is with a signature like
Function myUDF(param1 As Type1, ParamArray paramRest() As Variant) As MyType
but the condition that the ParamArray must have an even number of elements (ideally even Typed). Is this at all possible?
For example if you try to enter =SUMIFS(A:A,B:B,1,C:C)
into a cell, Excel will complain about using the wrong number of arguments (because the ParamArray would be Array(Range("B:B"),1,Range("C:C"))
and thus have an odd number of elements). I want the same behaviour for myUDF
.
Currently I handle it after the fact:
If UBound(paramRest) Mod 2 <> 1 Then
myUDF = CVErr(xlErrValue)
Exit Function
End If
But that feels "dirty".