VBA interdependent listboxes

Samir Ranjan Bhowmik 1 Reputation point
2021-10-25T07:27:02.577+00:00

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]  
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,454 questions
0 comments No comments
{count} votes