Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Remove Item from Listbox by Item Name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Randy - 19 Sep 2007 05:24 GMT
This one has to be really easy, but I can't track it down.  I know how
to remove an item from a listbox using its index value, but how do I
remove it by directly referring to the name of the item?  Example:

lbx1.RemoveItem ("DeleteThis")

This line errors out as an invalid argument.

Please help.

Thanks,
Randy
Doug Glancy - 19 Sep 2007 06:02 GMT
Randy,

You have to loop through the list items.  If you had a CommandButton1 on
your form, this sub would remove an item called "Doug":

Private Sub CommandButton1_Click()
Dim i As Long
For i = 0 To Me.ListBox1.ListCount - 1
   If Me.ListBox1.List(i) = "Doug" Then
       Me.ListBox1.RemoveItem (i)
       Exit Sub
   End If
Next i
End Sub

In some situations it makes sense to clear the list, e.g.,
Me.ListBox1.Clear, and then repopulate the Listbox.

hth,

Doug

> This one has to be really easy, but I can't track it down.  I know how
> to remove an item from a listbox using its index value, but how do I
[quoted text clipped - 8 lines]
> Thanks,
> Randy
Randy - 19 Sep 2007 07:01 GMT
I know how do that easily enough.  It just seems like a lot of
unnecessary lines to process, but oh well.

Thanks for your help.
Randy
Doug Glancy - 19 Sep 2007 14:36 GMT
Randy,

I agree!

Doug

>I know how do that easily enough.  It just seems like a lot of
> unnecessary lines to process, but oh well.
>
> Thanks for your help.
> Randy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.