Multiple "Multiple Selection" ListBoxes in a VBA Userform

DylanInvice

New Member
Joined
Jul 5, 2017
Messages
1
Hello Everyone,

I am currently working in an internship where I must create excel VBA userforms, intended for clients. In these userforms, there are comboboxes and textboxes all which correctly transfer responses into an excel sheet. However, I have multiple “multiple selection” list boxes in which the information is copied over multiple times. The first list box selections appear in all subsequent list box cells. If my five listboxes were each assigned an integer from 1 to 5, the results to these listboxes would be displayed in the following way: [1],[1+2],[1+2+3], [1+2+3+4],[1+2+3+4+5]
Below I have included the code that I am currently using. I am trying to stop the responses from appearing in subsequent cells. Any help would be greatly appreciated! Thank you for your time.


Private Sub cmdOK_Click()


Dim listitems As String, i As Long


'find the next empty row
Sheets("Investor").Select
Nextrow = Application.WorksheetFunction.CountA(Range("B:B")) + 1
Cells(Nextrow, 2) = CoName.Text
Cells(Nextrow, 3) = Loc.Text
Cells(Nextrow, 4) = ComBoINVtype.Text

With Industry
For i = 0 To .ListCount - 1
If .Selected(i) Then listitems = listitems & .List(i) & ", "
Next i
End With

Cells(Nextrow, 5) = Left(listitems, Len(listitems) - 2)

With Sector

For i = 0 To .ListCount - 1

If .Selected(i) Then listitems = listitems & .List(i) & ", "
Next i
End With

Cells(Nextrow, 6) = Left(listitems, Len(listitems) - 2)

With Area
For i = 0 To .ListCount - 1
If .Selected(i) Then listitems = listitems & .List(i) & ", "
Next i
End With

Cells(Nextrow, 7) = Left(listitems, Len(listitems) - 2)

With Stage
For i = 0 To .ListCount - 1
If .Selected(i) Then listitems = listitems & .List(i) & ", "
Next i
End With

Cells(Nextrow, 8) = Left(listitems, Len(listitems) - 2)

With Size
For i = 0 To .ListCount - 1
If .Selected(i) Then listitems = listitems & .List(i) & ", "
Next i
End With

Cells(Nextrow, 9) = Left(listitems, Len(listitems) - 2)

Close Userform1

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top