Unselect all selected items in a ListBox


Posted by beth on February 13, 2002 11:57 AM

Unselect all selected items in a ListBox

I would appreciate instructions on how to programmatically unselect all the selected items in a ListBox in a UserForm.

-b

Posted by Jim on February 13, 2002 12:50 PM

Posted by beth on February 13, 2002 1:55 PM

I have a UserForm that contains a ListBox which contains various names. When the ListBox?s MultSelect property is other than 0, a user can use the mouse to select / highlight multiple names in the ListBox. Clicking an enter button then fills a range with the selected / highlighted items; yet, the items in the ListBox remain selected / highlighted until the user clicks on that particular name to unselect / unhighlight that particular name. -b

Posted by Ivan F Moala on February 14, 2002 12:51 AM

try this;

Dim x As Integer
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
ListBox1.Selected(x) = False
End If
Next

MS Help:Note;
If you use the MultiSelect property to create a ListBox that allows multiple selections, the Selected property of the ListBox (rather than the ListIndex property) identifies the selected rows. The Selected property is an array with the same number of values as the number of rows in the ListBox. For each row in the list box, Selected is True if the row is selected and False if it is not. In a ListBox that allows multiple selections, ListIndex returns the index of the row that has focus, regardless of whether that row is currently selected.

HTH


Ivan



Posted by beth on February 14, 2002 7:21 AM

thank you

-b