Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox3.ListIndex = ListBox3.ListCount -- How to select the last item in a Listbox?
Hey,
I've been messing with all sorts of methods to get this to work correctly and for some reason it just doesn't seem to want to work correctly. All I want the code to do is to simply select the last item visible in a listbox. I've tried all sorts of combinations of logic but nothing is working correctly. I figured the code... ListBox3.ListIndex = ListBox3.ListCount Would work but it doesn't seem to want to and gives me an error message saying "Could not set the ListIndex property. Invalid property value." ERROR 308. Not sure if it matters but the list box has some thing like 500 diffrent choices to choose from...I'm simply looking for a button that will let me have the end user go to the bottom of the list. Any help is greatly appreciated. -Shaka215 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox3.ListIndex = ListBox3.ListCount -- How to select the last item in a Listbox?
The ListIndex property of a ListBox is 0-based, not 1-based. Therefore, the
first item in the list is ListIndex = 0, the second item is ListIndex = 1, and so on to the last item in the list = ListCount - 1. Thus, change ListBox3.ListIndex = ListBox3.ListCount to With ListBox3 If .ListCount 0 Then .ListIndex = .ListCount - 1 End If End With -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) wrote in message oups.com... Hey, I've been messing with all sorts of methods to get this to work correctly and for some reason it just doesn't seem to want to work correctly. All I want the code to do is to simply select the last item visible in a listbox. I've tried all sorts of combinations of logic but nothing is working correctly. I figured the code... ListBox3.ListIndex = ListBox3.ListCount Would work but it doesn't seem to want to and gives me an error message saying "Could not set the ListIndex property. Invalid property value." ERROR 308. Not sure if it matters but the list box has some thing like 500 diffrent choices to choose from...I'm simply looking for a button that will let me have the end user go to the bottom of the list. Any help is greatly appreciated. -Shaka215 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox3.ListIndex = ListBox3.ListCount -- How to select the last item in a Listbox?
On Mar 7, 8:08 pm, "Chip Pearson" wrote:
The ListIndex property of a ListBox is 0-based, not 1-based. Therefore, the first item in the list is ListIndex = 0, the second item is ListIndex = 1, and so on to the last item in the list = ListCount - 1. Thus, change ListBox3.ListIndex = ListBox3.ListCount to With ListBox3 If .ListCount 0 Then .ListIndex = .ListCount - 1 End If End With -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLCwww.cpearson.com (email address is on the web site) wrote in message oups.com... Hey, I've been messing with all sorts of methods to get this to work correctly and for some reason it just doesn't seem to want to work correctly. All I want the code to do is to simply select the last item visible in a listbox. I've tried all sorts of combinations of logic but nothing is working correctly. I figured the code... ListBox3.ListIndex = ListBox3.ListCount Would work but it doesn't seem to want to and gives me an error message saying "Could not set the ListIndex property. Invalid property value." ERROR 308. Not sure if it matters but the list box has some thing like 500 diffrent choices to choose from...I'm simply looking for a button that will let me have the end user go to the bottom of the list. Any help is greatly appreciated. -Shaka215- Hide quoted text - - Show quoted text - Thanks Chip! The code worked great! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
XL 2003: ListBox ListCount (and other) properties missing from Local Variables window | Excel Programming | |||
ListBox and ListIndex | Excel Programming | |||
select listbox item automatically | Excel Programming | |||
Select an item in a listbox using code | Excel Programming | |||
listbox.value not equal to listbox.list(listbox.listindex,0) | Excel Programming |