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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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