Function to add different values

D

Douglas

I need one function that adds values that are not equal.

Like this:
3
3
3
4
4
5
5

I need a formula that will go to add value 3+4+5.
Only different numbers between itself.
Which are my options?
 
B

Bernard Liengme

Two possible ways - both assume cells are sorted.

Simple method with helper column
Assume cells are A1:A7
In B1 enter = A1
In B2 enter =IF(A2=A1,0,A2)
Copy down to B7
Find SUM(B1:B7)

User-defined function:
Function unique(myrange)
Dim mycount As Integer
Dim j As Integer
mycount = myrange.Count
unique = myrange(1)
For j = 2 To mycount
If myrange(j) <> myrange(j - 1) Then
unique = unique + myrange(j)
End If
Next j
End Function

Use with =UNIQUE(A1:A7)
 
Top