excel userforms que...
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] excel userforms question 2

7 Posts
4 Users
0 Reactions
62 Views
 mrmo
Posts: 10709
Free Member
Topic starter
 

I have a two comboboxes the contents of the second depend on what ws selected from the first

How can it be done? i assume it can be


 
Posted : 23/02/2010 3:13 pm
Posts: 36
Free Member
 

create your first combo box
In another cell (say A1) create a conditional link that gives you either a 0 or a 1 (or 2 or 3 depending on the number of different fill lists you propose for your second combo box) depending on the selection from your first combo box.

for your second combo box create your two (or more) fill lists in say, b1:b5 and c1:c5 etc

now go to Insert>Name>Define and give a name to your second combo box fill list volatile range (say combo2list) and define it as =OFFSET(Sheet1!$B$1, 0, Sheet1!$A$1, 5, 1)

this makes the range change according to the number of columns it should jump right (driven by the first combi result in A1) to retrieve the dro pdown list from.

email me if you want a demo xls file to show you.


 
Posted : 23/02/2010 3:47 pm
 mrmo
Posts: 10709
Free Member
Topic starter
 

I was hoping that there was a way to keep it in the userform rather than calling between the userform and the worksheets


 
Posted : 23/02/2010 3:54 pm
Posts: 36
Free Member
 

ahh, sorry. Im not very good with standalone forms.
Probably need to do it in the VBA then wont you?


 
Posted : 23/02/2010 3:57 pm
Posts: 2
Free Member
 

you mean in VBA?
I would have the second list in a collection then update the collection using when the first list has changed.

SOOOooo

If you choose 2 in the fist box
you populate your collection with the values for 2, then load them into the combobox values.


 
Posted : 23/02/2010 3:58 pm
Posts: 36
Free Member
 

this any use?
http://www.contextures.com/xlUserForm02.html


 
Posted : 23/02/2010 4:02 pm
 mrmo
Posts: 10709
Free Member
Topic starter
 

thanks stoner, looks just the thing. Will investigate more tomorrow the snow is coming and i have better things to do than watch it fall.


 
Posted : 23/02/2010 4:09 pm
Posts: 6332
Free Member
 

when the first combobox is used it runs some VBA code which changes the ListFillRange of the second

So, in the code for combobox1

Private Sub ComboBox1_Change()

ComboBox2.ListFillRange = "A1:A10"

End Sub

where the items you want to appear in combo2 are listed in cells A1:A10


 
Posted : 23/02/2010 4:16 pm