Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

how populate more than

Forum 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

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

View a unique list

You have a column with hundreds of entries, and you need to see what unique items are entered in it. Select any cell in that column, hold down Alt and press the down arrow: Excel produces an alphabetically-sorted list of unique entries in that column.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.