VBA: Copy items from Listbox

FrankRechter

New Member
Joined
Sep 21, 2011
Messages
10
Hello

I have a listbox in a userform with several numbers and I would like to select one of them and copy it so that I can paste it anywhere else in Windows.
If this is not possible, maybe the number could be copied to another textbox; then I could copy it myself.

Thanks in advance
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this:-
Code:
Private [COLOR="Navy"]Sub[/COLOR] ListBox1_Click()
[COLOR="Navy"]Dim[/COLOR] MyData [COLOR="Navy"]As[/COLOR] New DataObject
 [COLOR="Navy"]Set[/COLOR] MyData = New DataObject
  MyData.SetText ListBox1.Value
    MyData.PutInClipboard
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks for your reply, but this doesn't seem to do anything. I cannot paste anything anywhere else.

Could a command button help?
 
Upvote 0
Is your list box called ListBox1. ??
You have to close the Userform to Paste.
Have you pasted the code into the Userform module for the ListBox Click Event. ???
 
Upvote 0
Hello again Mick.

No, my ListBox is called ListBox2, but I changed that already.

And yes, it's in the Userform module for the ListBox Click Event.

But even after closing the userform, it still doesn't work.
 
Upvote 0
If you have 2 columns in the listbox, how can you only copy the value from column 2 using this code?
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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