I'm trying to eliminate duplicates from one array, and store them into another, but this code doesn't seem to do it right. Can anyone give me a hand on fixing it. Thanks in advance.
[EDIT] Fixed subscript out of range error.
VB Code:
Option Explicit Dim A(9) As Long Dim B() As Long Dim I As Long, J As Long, K As Long Private Sub Form_Activate() A(0) = 0 A(1) = 1 A(2) = 2 A(3) = 3 A(4) = 4 A(5) = 5 A(6) = 6 A(7) = 7 A(8) = 8 A(9) = 9 ReDim B(0) As Long For I = 0 To UBound(A) For J = 0 To UBound(B) If A(I) <> B(J) Then If J = UBound(B) Then B(J) = A(I) K = K + 1 ReDim Preserve B(K) As Long End If ElseIf A(I) = B(J) Then Exit For End If Next J Next I For I = 0 To UBound(B) Print B(I) Next I End Sub






Mark Thread Resolved
Reply With Quote