Fill combobox2 based combobox1

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi
I want to create two combobox to both selectable and value of them fill automaticly when select value on another combobox, then I write for Combobox1:

Code:
Private Sub UserForm_Initialize()
    Me.ComboBox1.List = Worksheets("Sheet2").Range("B2:B600").Value
    End Sub
AND
Code:
Private Sub ComboBox1_Change()
Dim sValue As String
Dim r As Range, rAll As Range

sValue = ComboBox1

Set rAll = Sheet2.Range("B2:C600").End(xlDown)

For Each r In rAll
If r = sValue Then
ComboBox2 = r.Offset(0, 1)
End If
Next r
End Sub
I didn't Define any seperate code for Combobox2
But
1. Combobox1 don't show dropdown list when I type on it.
2. Combobox2 don't show value and dropdown list when Update value of Combobox1.
3. How to reverse this action for combobox2

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Code:
Private Sub ComboBox1_Change()
Dim sValue As String
Dim r As Range, rAll As Range

sValue = ComboBox1

Set rAll = Sheet2.Range("B2:B600").End(xlDown)'You just want to search Column B, right?

For Each r In rAll
If r = sValue Then
ComboBox2.AddItem r.Offset(0, 1)
End If
Next r
End Sub

I don't understand Item 3.
 
Upvote 0
Thanks Tinbendr
But I changed Range from "B2:C600" to "B2:B600" but result the same
and I don't anything in combobox2?
 
Upvote 0
I don't know why you say?
and where I define and Input code?
 
Upvote 0
You're going to have to step through the code (F8) and when you know you have a known match, see if the code adds it to the combobox.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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