question

SamirRanjanBhowmik-4401 avatar image
0 Votes"
SamirRanjanBhowmik-4401 asked

VBA interdependent listboxes

Hello,

Can anyone tell me if I could adapt the below code to other listboxes in an userform? Currently the selection in Listbox1 (Source) effect the filter changes to the listbox2 (Name of Project). Is it possible to make all the listboxes interdependent by changing the range reference?

 ![Private Sub ListBox1_Change()
   Dim a() As Variant
   Dim dic As Object
   Dim i As Long, j As Long
      
   Set dic = CreateObject("Scripting.Dictionary")
   a = Sheets("MDB").Range("A2", Sheets("MDB").Range("C" & Rows.Count).End(3)).Value
      
   ListBox2.Clear
   With ListBox1
     For i = 0 To .ListCount - 1
       If .Selected(i) Then
         For j = 1 To UBound(a, 1)
           If a(j, 1) = .List(i) Then
             dic(a(j, 3)) = Empty
           End If
         Next
       End If
     Next
     If dic.Count > 0 Then ListBox2.List = Application.Transpose(dic.keys)
   End With
   End Sub][1]


[1]: /answers/storage/attachments/143307-capture-2-listbox.jpg

office-vba-devoffice-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers