Trying to identify duplicates in an array of numbers. I found some variations of this on the Internet - seems like a practical option.
The value of i and j in line 8 is 0 and 1 respectively - this makes sense with a zero-based array. Unsure what's out of range.
The value of i and j in line 8 is 0 and 1 respectively - this makes sense with a zero-based array. Unsure what's out of range.
Code:
Public Function GetDuplicate() As Boolean
Dim arr()
Dim i As Long
Dim j As Long
arr = Array(123, 345, 654, 235, 94, 123)
For i = LBound(arr) To UBound(arr)
For j = i + 1 To UBound(arr)
If arr(i, 1) = arr(j, 1) Then 'error is "Subscript out of range"
GetDuplicate = True
Exit Function
End If
Next
Next
GetDuplicate = False
End Function