Solved

excel userform / combobox with dependent list

Posted on 2010-09-13
7
1,312 Views
Last Modified: 2013-11-26
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!
0
Comment
Question by:JKCC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 33661824
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.
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 33661878
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

0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 400 total points
ID: 33661884
Just use a two column list and write the second column back to the sheet (you can hide it in the combobox by setting its column width to 0) using:
Cells(1, 1).value = me.combobox1.list(me.combobox1.listindex, 1)
for example.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 33661894
Oops forget my code i didnt check that you are working on combox i thought you are working on listbox...
0
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 100 total points
ID: 33661900
Perhaps like this if you have defined the row source for the combo box.

Private Sub ComboBox1_Change()

Range("A1").Value = Application.Match(Me.ComboBox1.Value, Range(Me.ComboBox1.RowSource), 0)

End Sub
0
 

Author Comment

by:JKCC
ID: 33664760
ok, I will try these out . thanks
0
 

Author Closing Comment

by:JKCC
ID: 33671636
thanks again rorya and stephenJR. I implemented it and it worked! I did have the rowsource defined.

cheers!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question