Combobox to list only related item

kimberly090

Board Regular
Joined
May 22, 2014
Messages
99
I have a userfrom with 2 combobox

I wish to have my combobox2 will only list down the related item based on the value that being selected at combobox1

my combobox1 will contain the supplier list inside the data sheet while combobox 2 will only list the product which is related to the supplier.

others than that, the combobox1 will only show the unique supplier name only.

Here will be my data sheet information:

e5qqm8.jpg
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this Code

PHP:
Private Sub ComboBox1_Change()
Dim uniquelistCollection As New CollectionDim
 cellRange As Range
Dim keyString As String
ComboBox2.Clear
If ComboBox1.Text <> "" Then
    For Each cellRange In Sheet1.Range("B2:B7")
        If cellRange.Offset(0, -1).Text = ComboBox1.Text Then
            keyString = cellRange.Text & cellRange.Offset(0, -1).Text
            On Error Resume Next
            uniquelistCollection.Add cellRange, keyString
            If Err.Number = 0 Then ComboBox2.AddItem cellRange.Value
        End If
    Next cellRange
End If
End Sub

Private Sub UserForm_Initialize()
Dim uniquelistCollection As New Collection
Dim cellRange As Range
For Each cellRange In Sheet1.Range("A2:A7")
    On Error Resume Next
    uniquelistCollection.Add cellRange, cellRange.Text
    If Err.Number = 0 Then ComboBox1.AddItem cellRange.Value
Next cellRange
End Sub


Feel free to follow my blog for more tutorials, link
 
Upvote 0

Forum statistics

Threads
1,215,696
Messages
6,126,267
Members
449,308
Latest member
VerifiedBleachersAttendee

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