how populate more than

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

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

resolvedResolved · 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 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:

Create own ribbon tab - Excel 2010

a. In Excel click on the File tab
b. Select Options from left hand side
c. Choose the Customize Ribbon section
d. Click the New Tab button (below the list of tabs on the right hand side of the dialog box)
e. Select the New Tab (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
f. Select the New Group (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
g. Add commands to your tab and group by locating them on the list on the right hand side (remembering that you can change the list using the drop down box at the top of the list of commands) and clicking the Add button between the two panes to add them to your tab and group
h. You can rearrange the commands in your group, the groups on any tab or the tabs, using the up and down arrow buttons beside the list of tabs.
i. Click OK to apply your changes

View all Excel hints and tips


Server loaded in 0.09 secs.