Solved

excel userform / combobox with dependent list

Posted on 2010-09-13
7
1,318 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

Industry Leaders: 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!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

724 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