UserForm - Programmatically Select an Item

Posted on 2011-04-18
Last Modified: 2012-05-11
If ListBox2 contains items that were added by the User through an Add Button, and if the User then decides to Cancel all of the Items within ListBox2.  What is the syntax for Selecting an Item through VBA that will allow these items to be deleted.
If one of the items is selected manually, then it's pretty straightforward--see below
What is the Method for VBA to simulate the manual selecting of an Item within a Listbox?
For i = 0 To ListBox2.ListCount
                                    If ListBox2.ListCount > 0 Then _
                                        ListBox2.ListIndex = ListBox2.ListIndex - 1
                                     ListBox2.RemoveItem (ListBox2.ListIndex)
                                 Next i

Open in new window

Question by:Cook09
    LVL 85

    Accepted Solution

    Why do you need to select an item to delete it? If you want to remove all items, use the Clear method.

    Author Comment

    Well, that one was forgotten.  As with Arrays the syntax would be:

    Would that be correct?

    Author Closing Comment

    Sometimes there are so many trees that the forest gets hidden.     Thanks..

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
    No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now