Rowsource in combobox

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I want to load my comboboxes dynamically.

I have four comboxes and I am loading them with I rowsource.

What I want to do now is that, when I select an item from the first combobox, then inside the second combobox, show the list from the first combobox except the one selected in the first combobox . Then inside the third combobox, show the list from the second combobox except the one selected from the second combobox etc.

I hope this is achievable.

Thanks

Kelly
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Re: Rowsource in combobox challenge

Try this:-
Keep the "Rowsource" for combobox1, remove the other rowsources.
See the codes below for combobox1 & 2, repeat for other comboboxes.
NB:- the addition of the previous combobox selection for each new combobox.
Code:
Private Sub ComboBox1_Change()
Dim R As Range
Me.ComboBox2.Clear
For Each R In Range(Me.ComboBox1.RowSource)
    If Not R = Me.ComboBox1.Value Then
        Me.ComboBox2.AddItem R.Value
    End If
Next R
End Sub



Private Sub ComboBox2_Change()
Dim R As Range
Me.ComboBox3.Clear
For Each R In Range(Me.ComboBox1.RowSource)
    If Not R = Me.ComboBox2.Value And Not R = Me.ComboBox1.Value Then
        Me.ComboBox3.AddItem R.Value
    End If
Next R
End Sub
 
Upvote 0
Re: Rowsource in combobox challenge

Hi,
untested by try


Code:
Private Sub ComboBox1_Change()
    PopulateComboBox Me.ComboBox1, Me.ComboBox2
End Sub


Private Sub ComboBox2_Change()
    PopulateComboBox Me.ComboBox2, Me.ComboBox3
End Sub


Sub PopulateComboBox(ByVal SelectionBox As Object, ByVal FillBox As Object)
    Dim Item As Variant
    FillBox.Clear
    For Each Item In SelectionBox.List
      If SelectionBox.Value <> Item Then FillBox.AddItem Item
    Next
End Sub


Add other Comboboxes if needed


Dave
 
Upvote 0
Re: Rowsource in combobox challenge

Try this:-
Keep the "Rowsource" for combobox1, remove the other rowsources.
See the codes below for combobox1 & 2, repeat for other comboboxes.
NB:- the addition of the previous combobox selection for each new combobox.
Code:
Private Sub ComboBox1_Change()
Dim R As Range
Me.ComboBox2.Clear
For Each R In Range(Me.ComboBox1.RowSource)
    If Not R = Me.ComboBox1.Value Then
        Me.ComboBox2.AddItem R.Value
    End If
Next R
End Sub



Private Sub ComboBox2_Change()
Dim R As Range
Me.ComboBox3.Clear
For Each R In Range(Me.ComboBox1.RowSource)
    If Not R = Me.ComboBox2.Value And Not R = Me.ComboBox1.Value Then
        Me.ComboBox3.AddItem R.Value
    End If
Next R
End Sub


The combobox3 lists only the selected item I the first combobox
 
Upvote 0
Re: Rowsource in combobox challenge

I'm not quite sure what this means:-
The combobox3 lists only the selected item I the first combobox

What is "I" ???
 
Upvote 0
Re: Rowsource in combobox challenge

Hi,
untested by try


Code:
Private Sub ComboBox1_Change()
    PopulateComboBox Me.ComboBox1, Me.ComboBox2
End Sub


Private Sub ComboBox2_Change()
    PopulateComboBox Me.ComboBox2, Me.ComboBox3
End Sub


Sub PopulateComboBox(ByVal SelectionBox As Object, ByVal FillBox As Object)
    Dim Item As Variant
    FillBox.Clear
    For Each Item In SelectionBox.List
      If SelectionBox.Value <> Item Then FillBox.AddItem Item
    Next
End Sub


Add other Comboboxes if needed


Dave


Okay this works cool yet the fourth combobox I don't know how to end it.

I did
Code:
Private Sub ComboBox4_Change ()
PopulateCombobox Me.ComboBox4, Me.ComboBox4
End Sub
Yet did not work

Oops just found out I don't need that last private Sub

Thanks again
 
Last edited:
Upvote 0
Re: Rowsource in combobox challenge

I'm not quite sure what this means:-



What is "I" ???

Oh sorry that's typo.

"I" means in .

The item selected in the first combobox, shows as the only list in the third box
 
Upvote 0
Re: Rowsource in combobox challenge

dmt32's code, is a good solution, I should stick with that !!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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