Paste Values Selected in a Single-Column MultiSelect Enabled Listbox to Another Worksheet

Nicole17

New Member
Joined
Jul 3, 2013
Messages
18
I have a single-column multiselect enabled listbox that populates with data from a worksheet called "Testing". I would like to copy all the selected values in the listbox to column AG on another worksheet called "Admin" when the command button "OK" is pressed. Thanks in advance for any help!

I was trying using this code, but I keep getting a 438 run-time error (object doesn't support this property or method).
(This listbox is named ListBox1, the command button is CommandButtonYes. Very creative names, I know...)

Code:
Private Sub CommandButtonYes_Click()
Dim Thing1 As Long
With Application.ActiveSheet.ListBox1.List
    For Thing1 = 0 To .ListCount - 1
        If .Selected(Thing1) Then
            .List(Thing1, 0).Copy Destination:=Sheets("Admin").Cells(Cells.Rows.Count, "AG").Offset(1, 0)
        End If
    Next Thing1
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Managed to solve the problem on my own! For those interested, the code below works nicely.

Code:
Dim I As Long
Dim X As Long
X = 2
    For I = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(I) Then
            X = X + 1
            Range("Admin!AF" & X) = ListBox1.List(I) 'This range sets where the listbox data is pasted
        End If
    Next I
 
Upvote 0
You've attempted to merge the functions of a listbox and range object by using the .Copy Destination command. That copy command only works for Ranges, it is a Method of the range object. If you were to look at the Methods of a Listbox object, you will not find .Copy. You'll see things like additem, removeitem, and clear. If Excel 2007+ had a good help file anymore, you could easily see all the Methods available to a particular object. You should try to get familiar with the Object Browser in VBA, it's the icon below the menu item "Add Ins", it's a box with little shapes in it. Open it up, browse to Listbox, and read all the properties (finger icons), methods (green squares), and events (yellow lightning) available for that object. You will not see Copy there.

Anyways, to answer your question, try:

Sheets("Admin").Cells(Cells.Rows.Count, "AG").Offset(1, 0) = .List(Thing1,0)
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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