OldManDemosthenes
New Member
- Joined
- Apr 19, 2011
- Messages
- 38
I am having trouble displaying the results of a multiselect listbox. I would like the results to appear in column D rows 1, 2, etc... for however many selections I make. If possible, it would also be nice to leave row 1 blank as a header row.
I have a code that returns my selection with blank rows. For example, if I select the 5th, 10th, and 12th options in the listbox, the results are displayed in D5, D10, and D12.
Also, if I try to rerun the userform with different listbox selections, I get an error. I think this is because my selection list are not clearing, but honestly I have no clue.
My code is below. I have an output that lists all of my selections in a string in one cell. This part of the code runs perfectly and there are no errors associated with it.
I have a code that returns my selection with blank rows. For example, if I select the 5th, 10th, and 12th options in the listbox, the results are displayed in D5, D10, and D12.
Also, if I try to rerun the userform with different listbox selections, I get an error. I think this is because my selection list are not clearing, but honestly I have no clue.
My code is below. I have an output that lists all of my selections in a string in one cell. This part of the code runs perfectly and there are no errors associated with it.
Code:
Private Sub cbRun_Click()
Dim i As Long, cty As String
[INDENT]With lbCity[/INDENT]
[INDENT][INDENT]For i = 0 To .ListCount - 1[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]If .Selected(i) Then[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]cty = cty & ", " & .List(i, 1)[/INDENT][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]End If[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]Next i[/INDENT][/INDENT]
[INDENT]End With[/INDENT]
[INDENT]Cells(5, 1) = Left(cty, Len(cty) - 2)[/INDENT]
[INDENT]With lbCity[/INDENT]
[INDENT][INDENT]For i = 0 to .ListCount - 1[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]If .Selected(i) then[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]Cells(i,5)=.List(i)[/INDENT][/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]End If[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]Next i[/INDENT][/INDENT]
[INDENT]End With[/INDENT]
Unload Me
End Sub