Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Could someone please explain how to consistently set the first
item in the list box to selected (i.e. highlit) without needing to click on it? I've tried List1.Selected(0) = True and list1.listindex = 0 Both *seemed* to work, but occasionaly fail. Thanks - Kirk PS it's not a MultiSelect listbox. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Kirk,
Either one of the code you identified should work. Where do you have it in your code? Perhaps there are other lines that follow it which inadvertently changes the selection. Assuming you're trying to do this when the form loads, try putting it this way and place it as the last line of code in the UserForm_Initialize: If List1.ListCount 0 Then List1.ListIndex = 0 Other things to consider: 1. If you don't unload the form and just hide it, the next time you try to show it, the Initialize event will not fire and whatever was selected before you hid the form will be the one selected when it shows up again. 2. Step through your code to see if any lines are inadvertently changing the listbox selection. "kirkm" wrote: Could someone please explain how to consistently set the first item in the list box to selected (i.e. highlit) without needing to click on it? I've tried List1.Selected(0) = True and list1.listindex = 0 Both *seemed* to work, but occasionaly fail. Thanks - Kirk PS it's not a MultiSelect listbox. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am wondering if placing the reset command in the code for the click event
wouldn't be better than in the initialize event. It is the click event that selects the last ListIndex item, so if after the selection it is reset to 0, the first item should be in the window for the next use, whether or not the initialize event runs. Or am I out in left field? "Vergel Adriano" wrote: Kirk, Either one of the code you identified should work. Where do you have it in your code? Perhaps there are other lines that follow it which inadvertently changes the selection. Assuming you're trying to do this when the form loads, try putting it this way and place it as the last line of code in the UserForm_Initialize: If List1.ListCount 0 Then List1.ListIndex = 0 Other things to consider: 1. If you don't unload the form and just hide it, the next time you try to show it, the Initialize event will not fire and whatever was selected before you hid the form will be the one selected when it shows up again. 2. Step through your code to see if any lines are inadvertently changing the listbox selection. "kirkm" wrote: Could someone please explain how to consistently set the first item in the list box to selected (i.e. highlit) without needing to click on it? I've tried List1.Selected(0) = True and list1.listindex = 0 Both *seemed* to work, but occasionaly fail. Thanks - Kirk PS it's not a MultiSelect listbox. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As an after thought, it would be necessary to have executed any use of the
value of the current ListIndex selection prior to the reset if the reset is put into the ListBox click event. "Vergel Adriano" wrote: Kirk, Either one of the code you identified should work. Where do you have it in your code? Perhaps there are other lines that follow it which inadvertently changes the selection. Assuming you're trying to do this when the form loads, try putting it this way and place it as the last line of code in the UserForm_Initialize: If List1.ListCount 0 Then List1.ListIndex = 0 Other things to consider: 1. If you don't unload the form and just hide it, the next time you try to show it, the Initialize event will not fire and whatever was selected before you hid the form will be the one selected when it shows up again. 2. Step through your code to see if any lines are inadvertently changing the listbox selection. "kirkm" wrote: Could someone please explain how to consistently set the first item in the list box to selected (i.e. highlit) without needing to click on it? I've tried List1.Selected(0) = True and list1.listindex = 0 Both *seemed* to work, but occasionaly fail. Thanks - Kirk PS it's not a MultiSelect listbox. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Comparing List A to List B and add what's missing from List B | Excel Discussion (Misc queries) | |||
create new list from list A, but with exclusions from a list B | Excel Worksheet Functions | |||
validation list--list depends on the selection of first list | New Users to Excel | |||
list 1 has 400 names List 2 has 4000. find manes from list 1 on 2 | Excel Worksheet Functions | |||
find names on list 1 in list 2. list 1 4000 names list 2 400 name | Excel Worksheet Functions |