PC Review


Reply
Thread Tools Rate Thread

Combobox list based on choice in previous combobox

 
 
Slim Slender
Guest
Posts: n/a
 
      2nd Aug 2011
I think I may be on to something here. I'm just not getting the code
right.

Num Comment
1 this is the comment for the first example of number 1.
1 This is the second comment for number one.
2 This is the only comment for nymber 2.
3 Comment for number 3
5 First comment for number 5
5 Second comment for number 5.
5 Third comment for number 5.
6 Only comment for number 6.
7 One of two comments for number 7.
7 The other comment for number 7.

I have a table or range that looks like above. Notice repeated numbers
in first column.
I use a little procedure to get only the unique values in Num column
to populate a combobox.
The next thing would be to select one of those numbers, 5 for example,
and populate a combobox
with only the three comments associated with that number. It occurred
to me that I could use the same
approach of defining and then adding items selectively based on a
certain criterion as in the first combobox. Below is my attempt but it
doesn't quite work.

Private Sub ComboBox5_Change()

Dim rng As Range, i As Long
Dim SelectedComments As New Collection, Item

For i = 1 To
Worksheets("Sheet2").Range("ReferenceGuide").Rows.Count
Set rng = Worksheets("Sheet2").Cells(i, 2)
If rng.Offset(0, -1).Value = ComboBox5.Value Then
SelectedComments.Add rng.Value, CStr(rng.Value)
End If
Next

For Each Item In SelectedComments
UserForm1.ComboBox6.AddItem Item
Next Item
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox list based on choice in previous combobox Slim Slender Microsoft Excel Programming 0 2nd Aug 2011 11:16 AM
Combobox items based on choice in previous combobox Slim Slender Microsoft Excel Programming 0 2nd Aug 2011 03:52 AM
Limit ComboBox list by previous ComboBox results David Microsoft Access Form Coding 1 7th Aug 2009 07:09 PM
Re: Please help me with updating a form combobox (or table field) based on the choice of a different form combobox Ken Snell \(MVP\) Microsoft Access Forms 0 8th Oct 2007 12:37 AM
Values contained in value list of second combobox based on value selected in first combobox. Anthony Microsoft Access Forms 16 6th Mar 2004 04:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:45 AM.