Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last Item of Listbox not getting displayed Raj Excel Discussion (Misc queries) 0 April 22nd 08 10:58 AM
Adding item in listbox volabos Excel Worksheet Functions 0 December 3rd 07 11:47 AM
Adding item in listbox volabos Excel Worksheet Functions 0 December 3rd 07 11:27 AM
Item order in ListBox [email protected] Excel Discussion (Misc queries) 1 June 16th 06 01:15 PM
The value of a ListBox Item TK Excel Programming 2 August 20th 04 06:17 AM


All times are GMT +1. The time now is 02:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"