Link to home
Start Free TrialLog in
Avatar of JKCC
JKCCFlag for Australia

asked on

excel userform / combobox with dependent list

Hi experts,

I have a combo box on a userform that the user can choose a colour, e.g.  red, green, blue etc. how do i create a dependent list so that when colour red is selected, the number 4 writes to sheet 1 instead of the colour?.  THe users do not know the codes/assigned number but do know the colour. Can a dependent list be created on a userform? If so, how and how can i force the code to write the number rather than the colour?

This is a very simplified dummy example as I can't post the spreadsheet due to confidentiality.

My list is as follows:
Colours / Code
Blue              1
Orange      2
Green      3
Red              4

thanks heaps!
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Post a workbook with dummy data. How are you populating your combo box list? If you have a list in the spreadsheet you could use VLOOKUP or similar.
Avatar of Saurabh Singh Teotia
Assuming the listbox is a multiple listbox then you can give the following code in the listbox change event...
Also i have assumed that you know the series order of the listbox and it as per shown here in your example...This will give value in the range a1 of your sheet.
Saurabh...


dim iItem as long

  For iItem = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(iItem) = True Then
range("A1").Value=iItem+1
exit sub
end if
Next iItem

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops forget my code i didnt check that you are working on combox i thought you are working on listbox...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JKCC

ASKER

ok, I will try these out . thanks
Avatar of JKCC

ASKER

thanks again rorya and stephenJR. I implemented it and it worked! I did have the rowsource defined.

cheers!