|
-
Aug 15th, 2007, 02:06 AM
#1
Thread Starter
New Member
[exel] How to count different number?
Dear all,
here is the case:
I have some rows with six columns each.
does any body know how to count how many different number in each row?
ex: 1 - 3 - 1 - 2 - 4 - 5 >> 5 unique numbers
1 - 2 - 3 - 2 - 2 - 4 >> 4 unique numbers and so on.
Last edited by serunting; Aug 15th, 2007 at 10:02 PM.
-
Aug 15th, 2007, 02:49 PM
#2
Re: [exel] How to count different number?
Try this:
Code:
Public Sub test()
Dim Values() As Single
Dim i As Integer
ReDim Values(5)
For i = 0 To 5
Values(i) = Cells(1, i + 1).Value
Next i
MsgBox ("You have " & different_values(Values) & " values!")
End Sub
Public Function different_values(Values() As Single) As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim Check As Boolean
j = 0
Check = False
Do
For i = j To UBound(Values) - 1
If Values(j) = Values(i + 1) Then
For k = i + 1 To UBound(Values) - 1
Values(k) = Values(k + 1)
Next k
ReDim Preserve Values(UBound(Values) - 1)
Check = True
Exit For
End If
Next i
If Check = True Then
j = 0
Else
j = j + 1
End If
Check = False
Loop Until j = UBound(Values)
different_values = UBound(Values) + 1
End Function
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|