Sum Unique/Distinct Values in Excel:-
Public Function DISTINCTSUM(Rg As range)
Dim rCell As range
Dim cCells As New Collection
Dim vValue As Variant
' create a unique no duplicate value collection
For Each rCell In Rg
On Error Resume Next
cCells.Add rCell.Value, CStr(rCell.Value)
Next rCell
' sum all the data in previous collection
For Each vValue In cCells
DISTINCTSUM = vValue + DISTINCTSUM
Next vValue
Set cCells = Nothing
End Function
No comments:
Post a Comment