Copy first value from listbox and paste to sheet

femma

Board Regular
Joined
Jul 13, 2016
Messages
156
Hi!

I have a Userform with multiple listboxes. The first listbox lists all the sheets in the workbook. Two buttons let the user transfer the chosen sheets to Listbox1 and Listbox3.
After having the sheet names in both listboxes I would like to just copy the values in the listboxes to cells D1 and D2 in Sheet1.
Unfortunately it doesn't work. Here is the bit of code that should do the copy paste-part
Code:
Private Sub CommandButton3_Click()
Dim myvalue As String
Dim tmpMsg As String
Dim i As Long


 
 ThisWorkbook.Activate
 With ThisWorkbook
 
Dim TheArray As Variant
 Dim TheRange As Range

TheArray = ListBox1.List(0)


 Set TheRange = Range("D1")

TheArray = ListBox3.List(0)


 Set TheRange = Range("D2")

TheRange = TheArray


 End With

So basically it should always copy the first entry in the listbox.

Thanks for your help :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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