Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
XL 2003: ListBox ListCount (and other) properties missing from Local Variables window Michel S. Excel Programming 3 February 14th 07 07:35 PM
ListBox and ListIndex mtm4300 via OfficeKB.com Excel Programming 2 April 5th 06 05:56 PM
select listbox item automatically ilyaskazi[_71_] Excel Programming 3 September 14th 05 12:27 PM
Select an item in a listbox using code Fred Jacobowitz Excel Programming 2 August 23rd 04 03:27 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 01:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"