Multi-Select ListBox

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have a multiselect listbox on my Userform. That is, the property of this listbox is set to multi and the liststyle is set to Option. The purpose is to be able to select multiple rows from this listbox so I can delete the records selected from the worksheet. For example, the listbox shows records 1, 2 and 3 from sheet1. If, in the listbox I select items 1, 2 and 3 to be deleted, I have a loop to check which items were selected from the listbox and call a routine to delete the record on the worksheet. Actually, I have two loops. The first is to loop thru which item(s) were selected in the listbox, then another loop to find the matching record(s) in the worksheet. Here's the problem: When I delete the first matching record from the worksheet, the listbox items that were selected is now cleared. Therefore, only the first item that was selected is deleted. The second and third items that were selected is now cleared from the listbox. Is there another way to do this?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Dave, What about adding the selected names to another sheet and then run your delete code from the other sheet. The code here will place the selected names on a sheet called sheet4.

Private Sub cmdCopyValues_Click()
Dim lItem As Long
For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
Sheet4.Range("A65536").End(xlUp)(2, 1) = ListBox1.List(lItem)
ListBox1.Selected(lItem) = False
End If
Next
End Sub
 
Upvote 0
Pleased to read you have a working solution.
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,681
Members
449,249
Latest member
ExcelMA

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