Add unique values

 1999-08-14    Sum    0    53

The custom function below adds the unique values only from a given range:

Function SumUniqueValues(InputRange As Range) as Double
Dim cl As Range, UniqueValues As New Collection, uValue As Variant
    Application.Volatile
    On Error Resume Next
    For Each cl In InputRange
        UniqueValues.Add cl.Value, CStr(cl.Value)
    Next cl
    On Error GoTo 0
    SumUniqueValues = 0
    For Each uValue In UniqueValues
        SumUniqueValues = SumUniqueValues + uValue
    Next uValue
End Function
Example, add the unique values in the range A1:A100:

=SumUniqueValues(A1:A100)


Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.