Hi,
Sorry if this is a topic well discussed, but I have been working on this basic code to have it doing this:
I have a Listbox1 in which I was able to populate it with unique items (from columnB in Programmes worksheet) using a collection (that was a good achievement for me!)
Now, I want to populate a the Listbox2 with items (not repeated) from columnC, BUT only if the correspondent value on columnB is equal to listbox1.value.
Could you please help me finding a solution for this? I am just a beginner in VBA...
THANKS!
<script type="text/javascript">
<!--
Private Sub CommandButton2_Click()
Dim myList As Collection
Dim myVal As Variant
Set Programmes = Worksheets("Programmes")
Set ws = Worksheets("Tables")
Set myList = New Collection
'Clear listbox
ws.ListBox2.Clear
'Last used cell in the entry table
LR = Programmes.Cells(Rows.Count, 1).End(xlUp).Row
For X = 5 To LR
Set myCell = Programmes.Cells(X, 3)
If Programmes.Cells(X, 2) = ws.ListBox1.Value Then
myList.Add (myCell.Value), CStr(myCell.Value) 'RUN-TIME ERROR 457 - this key is already associated with an element of this collection
End If
Next X
On Error GoTo 0
For Each myVal In myList
ws.ListBox2.AddItem myVal
Next myVal
End Sub
//-->
</script>
Bookmarks