I have this one array and what I am trying to do is find after how many numbers is there a duplicate number. So if a list is: 5 4 6 3 5 Then it should display that the duplicate happens after 4 numbers. Here's my code: Option Explicit Dim ind As Integer Dim arrays() As Integer Dim size As Integer Dim i As Integer Private Sub Form_Load() Randomize size = 5 ReDim arrays(size) For ind = LBound(arrays) To UBound(arrays) arrays(ind) = Int(size * Rnd + 1) Next ind For ind = LBound(arrays) To UBound(arrays) List1.AddItem arrays(ind) Next ind Code (markup):
Would this be what you need? (add a button and paste the code) Private Sub Command1_Click() Dim i As Long Dim k As Long Dim itemvalue As String For i = 0 To List1.ListCount - 1 itemvalue = List1.List(i) For k = i + 1 To List1.ListCount - 1 If List1.List(k) = itemvalue Then MsgBox "Duplicate of item#" & CStr(i) & " found after " & CStr(k - i) & " items" Exit For End If Next k Next i End Sub Code (markup):