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
 

Forum statistics

Threads
1,081,793
Messages
5,361,316
Members
400,625
Latest member
Asraful Alam

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top