How do I enable multiple selection of items in user form list box and transfer the data to another sheet?

karmaLee

New Member
Joined
Nov 23, 2021
Messages
24
Office Version
  1. 2016
Platform
  1. Windows
I have a user form that contains list box. I want to be able to select multiple items from my list box and when I click the "OK" command button in the user form, I want the items selected to be transferred to another worksheet in the same workbook. I have attempted a code but my code only enabled the last item selected to be transferred. I want all items selected to be transferred.

Here is my code:
Dim i
With Sheet5
.Cells(newRow, 5) = ListBox1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
.Cells(newRow, 5) = ListBox1.List(i)
End If

Next i
End With
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
If ListBox1.Selected(i) Then
k=k+1
.Cells(newRow, 5) = ListBox1.List(k)
 
Upvote 0
Are you trying to put all the selected items into one cell, or multiple cells?
 
Upvote 0
How about
VBA Code:
.Cells(newRow, 5) = .Cells(newRow, 5) & ", " & ListBox1.List(i)
 
Upvote 0
Solution
How about
VBA Code:
.Cells(newRow, 5) = .Cells(newRow, 5) & ", " & ListBox1.List(i)
Hello Fluff, thank you for your code. The code works perfectly and just as I had intended. I appreciate your help! Have a great week ahead!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,348
Messages
6,124,425
Members
449,157
Latest member
mytux

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