?
Solved

UserForm - Programmatically Select an Item

Posted on 2011-04-18
3
Medium Priority
?
272 Views
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.
Example:
If one of the items is selected manually, then it's pretty straightforward--see below
However,
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

0
Comment
Question by:Cook09
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 35419561
Why do you need to select an item to delete it? If you want to remove all items, use the Clear method.
0
 

Author Comment

by:Cook09
ID: 35419822
Well, that one was forgotten.  As with Arrays the syntax would be:
  UserForm.ListBox2.Clear

Would that be correct?
0
 

Author Closing Comment

by:Cook09
ID: 35420457
Sometimes there are so many trees that the forest gets hidden.     Thanks..
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

621 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