ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   listbox remove Item (https://www.excelbanter.com/excel-programming/333515-listbox-remove-item.html)

Simon Shaw

listbox remove Item
 
I am trying to remove multiple selected items from a ListBox... the code:

myListBox.RemoveItem myListBox.ListIndex

only removes the last selected item. I have tried a number of things, but
keep getting bad results. Does anyone have an example of this?

Thanks

Simon Shaw

Norie

listbox remove Item
 

Simon

What else have you tried?

What you need to do is loop through each item in the list box and check
if it is selected then remove it if it is.

Code:
--------------------

Dim I As Integer

For I = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(I) = True Then
ListBox1.RemoveItem I
End If
Next I
--------------------


--
Norie
------------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...o&userid=19362
View this thread: http://www.excelforum.com/showthread...hreadid=384197


Tom Ogilvy

listbox remove Item
 
for an activeX Listbox

for i = listbox.Listcount -1 to 0 step -1
if listbox.Selected(i) then
listbox.RemoveItem i
end if
Next

--
Regards,
Tom Ogilvy


"Simon Shaw" <simonATsimonstoolsDOTcom wrote in message
...
I am trying to remove multiple selected items from a ListBox... the code:

myListBox.RemoveItem myListBox.ListIndex

only removes the last selected item. I have tried a number of things, but
keep getting bad results. Does anyone have an example of this?

Thanks

Simon Shaw




Doug Glancy

listbox remove Item
 
Simon,

Sub Test()

Dim i As Long

With Me.myListBox
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) = True Then
.RemoveItem i
End If
Next i
End With

End Sub


"Simon Shaw" <simonATsimonstoolsDOTcom wrote in message
...
I am trying to remove multiple selected items from a ListBox... the code:

myListBox.RemoveItem myListBox.ListIndex

only removes the last selected item. I have tried a number of things, but
keep getting bad results. Does anyone have an example of this?

Thanks

Simon Shaw





All times are GMT +1. The time now is 10:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com