Array Question - look for duplicates
Hi,
There's probably a far better way of doing this, but I've been playing around with the code below, and seeing I've got this far, how do you search though an array of values to see whether there are any duplicated values in the array?
John
EDIT: Let me clarify that a bit...we can assume that there are no existing duplicates in the array, but we want to check that any NEW entry(s) is not duplicating a previous entry.
Code:
Option Explicit
Private Sub Worksheet_Deactivate()
Dim Lost, i%, N%, BinaryNum!, BinarySum!
Dim MyArray(36) As Single
For N = 6 To 41 'rows 6 to 41
Worksheets("DB_36").Select
With Worksheets("DB_36").Rows(N)
Set Lost = .Find(What:="*", LookIn:=xlValues, searchorder:=xlByRows)
If Not Lost Is Nothing Then
BinarySum = 0
For i = 1 To 5
Set Lost = .FindNext(Lost)
BinaryNum = 2 ^ (Lost.Column)
'//BinarySum is a unique number if there are no duplicates
BinarySum = BinarySum + BinaryNum
Next i
MyArray(N - 5) = BinarySum
End If
End With
Next N
' If one of the array values is the same as another Then
MsgBox "You have duplicated entries ! - Change one of them"
' select the row with the last duplicated entry
' Else
' End If
End Sub