title: VBA Display in a listbox based on two dynamic comboboxes
body: <p>I would like to display the result of 2 comboboxes in a listbox but I don't know how to do it...</p>
  
  <p>Here's what I've got so far :</p>
  
  <p><a href="https://i.stack.imgur.com/f7uRv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f7uRv.png" alt="UserForm with comboboxes"></a>
  Depending on the left-hand combobox, it implies the results of the right-hand combobox.</p>
  
  <p>1/ I would like to display <strong>the package version</strong> ($E) and <strong>the package release</strong> ($F) of the package name <strong>selected</strong> on the right-hand combobox for the project <strong>selected</strong> on the left combobox, ("monitoring" in this example).</p>
  
  <p>2/ If I select "ALL" package name, I would like to display <strong>$E</strong> and <strong>$F</strong>.</p>
  
  <p>Here is my current code :</p>
  
  <pre><code>Private Sub CommanButton1_Click()
      Unload UserForm1
  End Sub
  
  Private Sub UserForm_Initialize()
      Dim ws As Worksheet, rCell As Range, Key
      Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
      Set ws = Worksheets("system-packages-installed")
      UserForm1.ComboBox1.Clear
      For Each rCell In ws.Range("B2", ws.Cells(Rows.Count, "B").End(xlUp))
          If Not Dic.exists(LCase(rCell.Value)) Then
              Dic.Add LCase(rCell.Value), Nothing
          End If
      Next rCell
      UserForm1.ComboBox1.AddItem "ALL"
      For Each Key In Dic
          UserForm1.ComboBox1.AddItem Key
      Next
  End Sub
  
  Private Sub ComboBox1_Click()
      Dim rCell As Range, Key
      Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
      Set ws = Worksheets("system-packages-installed")
      UserForm1.ComboBox2.Clear
      For Each rCell In ws.Range("B2", ws.Cells(Rows.Count, "B").End(xlUp))
          If rCell.Value = ComboBox1.Value Then
              If Not Dic.exists(LCase(rCell.Offset(, 1).Value)) Then
                  Dic.Add LCase(rCell.Offset(, 1).Value), Nothing
              End If
          End If
      Next rCell
      UserForm1.ComboBox2.AddItem "ALL"
      For Each Key In Dic
          UserForm1.ComboBox2.AddItem Key
      Next
  
  End Sub
  
  Private Sub ComboBox2_Click()
      'This is a test'
      With UserForm1.ListBox1
          .ColumnCount = 27
          .ColumnWidths = "50"
          .RowSource = "'system-packages-installed'!E:E"
      End With
  End Sub
  </code></pre>
  
  <p>If you have any question, do not hesitate to ask me.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit :</p>
  
  <p>Here is the table :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;style type="text/css"&gt;
  .tg  {border-collapse:collapse;border-spacing:0;}
  .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
  &lt;/style&gt;
  &lt;table class="tg"&gt;
    &lt;tr&gt;
      &lt;th class="tg-0pky"&gt;System_id&lt;br&gt;&lt;/th&gt;
      &lt;th class="tg-0pky"&gt;Machine&lt;/th&gt;
      &lt;th class="tg-0pky"&gt;package_name&lt;/th&gt;
      &lt;th class="tg-0pky"&gt;package_epoch&lt;/th&gt;
      &lt;th class="tg-0pky"&gt;package_version&lt;/th&gt;
      &lt;th class="tg-0pky"&gt;package_release&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;acl&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;2.2.51&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;14.el7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;alsa-lib&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;1.1.6&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;2.el7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;apg&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;2.3.0b&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;24.el7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;apr&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;1.4.8&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;3.el7_4.1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;apr-util&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;1.5.2&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;6.el7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;at&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;3.1.13&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;24.el7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="tg-0pky"&gt;1000010000&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;monitoring&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;audit&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;2.8.4&lt;/td&gt;
      &lt;td class="tg-0pky"&gt;4.el7&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>