![]() |
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 |
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 |
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! |
All times are GMT +1. The time now is 02:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com