Copy listbox selected items to a range in excel and compare against an existing range

tribalKitty

New Member
Joined
Jan 11, 2014
Messages
1
I have a listbox with about 15 items with multi-select enabled. I want to copy the selected items to a range in excel. However, if an item is unselected, it should be removed from the range as well.
I will be using these selected items to do a vlookup and set flags.


I have the following snippet, which kind of works. But, it repeatedly copies all the items selected. For eg if item 1 and 2 were selected, then item 3 was selected, it pastes item 1 and 2, then item 1,2, and 3 and so on. I want the selected values to be copied only once to a defined range in excel. What is the best way to do it?
Should I use an array to store the selected items then copy to a range? Will that eliminate the multiple copying of selected items?
Please help.




Also, what is the difference between events "Change" and "Click" of listbox?


Dim is as integer
Dim cur as String
For i = 0 To ListBox1.ListCount - 1


If ListBox1.Selected(i) Then


cur = ListBox1.List(i)


With Sheets("Sheet1")
.Range("d65536").End(xlUp).Offset(1).Value = cur
End With
End If


Next i



Thank you.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,216,134
Messages
6,129,070
Members
449,485
Latest member
greggy

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