Userform combobox source

Kiwi den

Board Regular
Joined
Feb 17, 2014
Messages
140
Office Version
  1. 365
Platform
  1. Windows
Hi all hope someone can help
I have a userform, that contains a 2 combo boxes, the first I want to use for "Suppliers Name" The second I would like the source for this to be determined by what is in combobox 1
Example.. if combobox 1 has FRED in it, then combobox 2 will only have options for what FRED sells, ditto if Combobox has Ben in it then Combobox 2 will have only have options for what BEN sells.
In the spreadsheet I have the formulas to achieve this, nut unsure how if possible this can be done in a userform

Your help appreicated
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,961
Office Version
  1. 365
Platform
  1. Windows
Here's an example of 2 dependent combobox:
2 combobox, dependent, userform, simple, dictionary, table.xlsm

the code:
VBA Code:
'====YOU MAY NEED TO ADJUST THE CODE IN THIS PART:====
'sheet's name where the list  is located.
Private Const sList As String = "Sheet1"
'Table name where the list  is located
Private Const tbl As String = "Table1"

Private Sub ComboBox1_Change()
      ComboBox2.Value = ""
End Sub

Private Sub ComboBox1_Enter()
Dim vList, d As Object, i As Long
vList = Sheets(sList).ListObjects("Table1").DataBodyRange.Columns("A")
    
    Set d = CreateObject("scripting.dictionary")
    d.CompareMode = vbTextCompare
    For i = LBound(vList) To UBound(vList)
          d(vList(i, 1)) = Empty
    Next
       ComboBox1.List = d.keys
End Sub


Private Sub ComboBox2_Enter()
Dim vList, d As Object, i As Long
vList = Sheets(sList).ListObjects("Table1").DataBodyRange.Columns("A:B")

    Set d = CreateObject("scripting.dictionary")
    d.CompareMode = vbTextCompare
    For i = LBound(vList) To UBound(vList)
        If UCase(vList(i, 1)) = UCase(ComboBox1.Value) Then d(vList(i, 2)) = Empty
    Next
       ComboBox2.List = d.keys
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,347
Messages
5,624,136
Members
416,012
Latest member
rockermom59

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top