98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » How to populate more than one multiselect listbox onto specified
How to populate more than one multiselect listbox onto specified
Resolved · Urgent Priority · Version 2010
Raani has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
How to populate more than one multiselect listbox onto specified
Hi,
I have created a userform which has 4 categories and a range multiselect listboxes under each category. Users will select as many of the options in each of these listboxes as needed.
I've determined the coding which takes all the selections made from listbox 1 and populates them into cell F2, with each selection separated by a comma.
The problem I'm having is when I repeat the coding for Listbox2 to populate in cell F3, it includes the items that were ticked in listbox1 and listbox2. Likewise if I use this coding for listbox3, all selected items from listbox1, 2 and 3 appear in the cell.
Here is the coding for listboxes 1 and 2:
Private Sub CommandButton1_Click()
Dim i As Long, txt As String, Flg As Boolean
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
Flg = True
txt = txt & "," & .List(i)
End If
Next
End With
If Flg Then
With Sheets("Sheet2")
.Range("F2").Value = Mid$(txt, 2)
End With
End If
With Me.ListBox2
For i = 0 To .ListCount - 1
If .Selected(i) Then
Flg = True
txt = txt & "," & .List(i)
End If
Next
End With
If Flg Then
With Sheets("Sheet2")
.Range("F3").Value = Mid$(txt, 2)
End With
End If
End Sub
Could you tell me what I need to include so that the selected items of each listbox are restricted to the specified cell?
Thank you for your help
Raani
RE: How to populate more than one multiselect listbox onto speci
Hi Raani
Thank you for your question. I have forwarded it to one of my colleagues who delivers VBA training. At the moment they are delivering training themselves so please bear with us as there will likely be a delay before they can reply.
Kind regards,
Andrew
RE: How to populate more than one multiselect listbox onto speci
Hi,
I'd be grateful if someone could come back to me on this please
Thanks
Raani
RE: How to populate more than one multiselect listbox onto speci
Hi Raani
Interesting quesion.
Sorry for my delay in posing back to you.
You might have spotted it by now! The variable txt needs to be reset before being loaded with the values from ListBox2.
To do that add
txt = ""
just before the line
With Me.ListBox2 ...
Hope that does the trick.
Doug Dunn
Best STL
RE: How to populate more than one multiselect listbox onto speci
Hi Doug,
Yes I worked it out eventually!
Thank you for coming back to me
Raani
RE: How to populate more than one multiselect listbox onto speci
That'a good.
Well done Raani !
Doug
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Create own ribbon tab - Excel 2010a. In Excel click on the File tab |