Function to add different values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top