populating one list/combobox based on the results of another

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi,

I'd be grateful if someone could help with what i think is probably quite a
simple thing (just not as simple as me).

I have a userform with two comboboxes; the data for these come from one
data-table. combobox1 is filled with the table heading data (ie, from a
single row) and this works fine; what i can't do is populate the the second
combobox with the column of data in the data-table below the relevant header
(as chosen in the first combobox). i want the population to be programmatic
/ dynamic as the table is likely to change over time.

hope someone can help, cheers,

tim
 
Tim said:
Hi,

I'd be grateful if someone could help with what i think is probably quite a
simple thing (just not as simple as me).

I have a userform with two comboboxes; the data for these come from one
data-table. combobox1 is filled with the table heading data (ie, from a
single row) and this works fine; what i can't do is populate the the second
combobox with the column of data in the data-table below the relevant header
(as chosen in the first combobox). i want the population to be programmatic
/ dynamic as the table is likely to change over time.

hope someone can help, cheers,

tim

apologies for replying to my own post - i've cobbled together something that
works (see below) - can anyone improve it, eg, i must be able to do it
without actually selecting cells? no worries if not, as i've got the thing
basically working now.

cheers

tim

Private Sub ComboBox1_AfterUpdate()

ComboBox2.Enabled = True
On Error Resume Next
Dim FindValue As String

FindValue = ComboBox1.Value
Application.Goto Reference:="rngsite"
Selection.Find(What:=FindValue, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select
UserForm1.ComboBox2.Clear
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Value = ""
UserForm1.ComboBox2.AddItem ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top