Userform combobox source

Kiwi den

Board Regular
Joined
Feb 17, 2014
Messages
143
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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

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
Back
Top