Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

excel userform / combobox with dependent list

Posted on 2010-09-13
7
Medium Priority
?
1,341 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 1600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

926 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