Solved

excel userform / combobox with dependent list

Posted on 2010-09-13
7
1,305 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
  • 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
Technology Partners: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

685 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