Hi all,
I have problems with my userform's listboxes. I have two listboxes, and I want second listbox's values to be dependent on first listbox's values.
And even more complicated, I need second listbox's values to be dependent on values on certain matrix.
In that matrix, row headings are listbox1's values and column headings are listbox2's values. How ever there are blanc cells on that matrix aswell. So if there is a blanc cell(s) on a row which (heading) is selected at listbox1, then I don't want that column (heading) which intersects with the blanc cell to be included to my listbox2 values.
Finally I want to insert the selected values from listboxes and the value from the intersection of those listbox values (headings) on that matrix to worksheet.
I included an attachment, where you can see my point better. However, as you can see, now the listbox values are not dependent on that matrix. Otherwise it is working like I want it to work.
-Juhanen-
Hi,
I hope someone can help with my question, because I'm still stuck on it.
Thanks
-juhanen-
Bump no response
Last edited by Juhanen II; 08-18-2008 at 03:11 AM.
What exactly do you want to display in ListBox2? Say Wed is chosen in ListBox1 do you want ListBox2 to contain 5,7,11 or w2,w3,w4?
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Hi Roy,
Sorry if I failed to be spesific...
For example if Wed is chosen in Listbox1 , then I want ListBox2 to contain w2,w3,w4
Thanks,
-Juhanen-
Remove the RowSource of ListBox2 in the Properties. Then use the Click event of ListBox1
Private Sub ListBox1_Click() Dim rng As Range Dim cl As Range Dim R As Long R = Me.ListBox1.ListIndex + 2 With Sheet2 Set rng = .Range(.Cells(R, 2), .Cells(R, 6)) End With With Me.ListBox2 .Clear For Each cl In rng If Not IsEmpty(cl) Then .AddItem "w" & cl.Value Next cl End With End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Thanks Roy. However, there's a mistake in the code:
For example if Wed is chosen in Listbox1 , instead of w2,w3,w4 ListBox2contains w5, w7, w11. (So instead of headings of the matrix, "w"+nonblanc values of the specified row are selected to Listbox2)
Secondly, I would be thankful if the code would use range names when referring to ranges, so that I could use the same code in different matrixes.
-Juhanen-
bump no response
There's no mistake in the code, it does exactly what I thought that you wanted. However, I think you want the header row so I have changed the code
Private Sub ListBox1_Click() Dim rng As Range Dim cl As Range Dim R As Long R = Me.ListBox1.ListIndex + 2 With Sheet2 Set rng = .Range(.Cells(R, 2), .Cells(R, 6)) End With With Me.ListBox2 .Clear For Each cl In rng If Not IsEmpty(cl) Then .AddItem Cells(1, cl.Column).Value Next cl End With End SubYou will need to adapt the code to suit whatever ranges you want to useSecondly, I would be thankful if the code would use range names when referring to ranges, so that I could use the same code in different matrixes.
-Juhanen-
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Thanks,
However, the new code doesn't work. (There is no error message, but second listbox is fully empty no matter which value you select form listbox1)
-Juhanen-
It works fine in the example workbook that you uploaded.
Try this slight amendment
Private Sub ListBox1_Click() Dim rng As Range Dim cl As Range Dim R As Long R = Me.ListBox1.ListIndex + 2 With Sheets("Data") Set rng = .Range(.Cells(R, 2), .Cells(R, 6)) End With With Me.ListBox2 .Clear For Each cl In rng If Not IsEmpty(cl) Then .AddItem Sheets("Data") _ .Cells(1, cl.Column).Value Next cl End With End Sub
Last edited by royUK; 08-19-2008 at 07:42 AM.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Thanks RoyUK
Now it works well. U saved my day.
-Juhanen-
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks