ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Add unique values

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: =SumUniqueValues(A1:A100) will add the unique values in the range A1:A100.

 

Document last updated 1999-08-14 12:44:13      Printerfriendly version

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address