title: VBA .Auto populate unique values in 2nd combobox based on 1st combobox data
body: <p>I need to populate two combo boxes from excel sheet, the data will be like below:</p>
  
  <pre>
  Column   | A Column B
  ----------------------
  A | 1
  A | 2
  A | 3
  A | 3
  A | 5
  B |10
  B | 11
  B | 12
  A | 1 
  A | 5
  A | 2
  </pre>
  
  <p>So from the above data, one combo box should hold unique values A &amp; B.</p>
  
  <p>On selecting a value from the 1st combo box A or B, respective values should be populated in 2nd combo box.</p>
  
  <p>So the data should be like below:</p>
  
  <p>If A is selected in the 1st combo box, then 2nd combo box should only show the values 1,2,3,4 &amp; 5.
  If B is selected in the 1st combo box, then 2nd combo box should only show the values 10,11 &amp; 12.</p>
  
  <p>for that i have following code  : -</p>
  
  <pre><code> Private Sub ComboBox1_Change()
  
   Dim rng As Range
   Set rng = Sheet2.Range("B2", Sheet2.Cells(Rows.Count, "b").End(xlUp))
  
   Set oDictionary = CreateObject("Scripting.Dictionary")
   Sheet1.ComboBox2.Clear
  
   With Sheet1.ComboBox2
  For Each cel In rng
  If ComboBox1.Value = cel.Offset(, -1).Value Then
  
          oDictionary(cel.Value) = 0
          .AddItem (cel.Value)
  
      End If
     Next cel
     End With
    End Sub
  
  
    Private Sub ComboBox1_DropButtonClick()
  
    Dim rng As Range
  
  
  
   Set rng = Sheet2.Range("A2", Sheet2.Cells(Rows.Count, "A").End(xlUp))
  
   Set oDictionary = CreateObject("Scripting.Dictionary") 'to put uniqe values     from rng variable to combo box1
    With oDictionary
    For Each cel In rng
    If Not .exists(cel.Value) Then
          .Add cel.Value, Nothing
      End If
    Next cel
  
  Sheet1.ComboBox1.List = .keys
  End With
  End Sub
  </code></pre>
  
  <p>problem is that it combobox does not shows unique values .</p>
  
  <p>how  i can get unique values in combobox2 .</p>
  
  <p>you can ignore my coding and provide simplest way to do above said task ...</p>