Am trying to compare a column range ("B2:B500") from sheet with listbox items and display items which are not in listbox. I want to copy the items which are not present in listbox1 but present in column range in sheet4 to another listbox i.e, listbox2. Someone please help me here
I will not be able to share data, but my code is as below which is giving considering only first item in a listbox1
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'find last row
'LastRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Row
'clear listbox
Me.ListBox2.Clear
'not just one value, but which ever were selected
For X = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(X) = True Then
'it is selected
curval = Me.ListBox1.List(X)
For Y = 2 To 1000
If curval <> Sheet4.Cells(Y, "b") Then
'found a match; populate listbox2
With ListBox2
.AddItem Sheet4.Cells(Y, "b")
.Font.Size = 8
End With
End If
Next Y
End If
Next X
End Sub
I will not be able to share data, but my code is as below which is giving considering only first item in a listbox1
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'find last row
'LastRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Row
'clear listbox
Me.ListBox2.Clear
'not just one value, but which ever were selected
For X = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(X) = True Then
'it is selected
curval = Me.ListBox1.List(X)
For Y = 2 To 1000
If curval <> Sheet4.Cells(Y, "b") Then
'found a match; populate listbox2
With ListBox2
.AddItem Sheet4.Cells(Y, "b")
.Font.Size = 8
End With
End If
Next Y
End If
Next X
End Sub