How do you use a multiselect listbox1 to place data in a specific cell using VBA

knharris75

New Member
Joined
Jun 21, 2010
Messages
2
I have a userform that contains a listbox that needs to do the following:
1. Allow multiple data elements to be selected
2. Copy those selected items to the active cell
3. Place all the data elements in the active cell.

Here is the code I have written, I just need to figure out how to make it work for multiselection, HELP ME PLEASE!!!!!!!!!!!

Private Sub CommandButton2_Click()
Sheet2.Activate
ActiveCell.Offset(0, 0).Range("A1").Select
ActiveCell.Value = UserForm1.ListBox1.Value
UserForm1.ListBox1.Value = vbNullString
UserForm_Click
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
Private Sub CommandButton2_Click()
Dim i As Long
Dim data As String

	With UserForm1.ListBox1
        For i = 0 To .ListCount - 1 
            If .Selected(i) Then 
                data = data & .List(i) & " " 
            End If 
        Next i 
    End With 

    Sheet2.Range("A1").End(xlDown).Offset(1, 0).Value2 = data
End Sub
 
Upvote 0
XLD. thanks for the swift response. i have entered the code you suppplied and I recieve a run time error "1004" Application-defined or object defined error. What am I doing wrong?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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