Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Problem with ListBox, List Index

Excel 2003
I have a 2 column, populated ListBox.
The ListBox selection routine includes the code:-
MyIndex = UserForm1.ListBox1.ListIndex
(under <<Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift
As Integer, _
ByVal X As Single, ByVal Y As Single))
and MyIndex is a Publically declared variable.

The purpose of recording the user's selection in the MyIndex variable
is so that it can be used in the UserForm Initialize process to
highlight the last selection.

The Initialize routine therefore includes the code:-
UserForm1.ListBox1.ListIndex = MyIndex
(under <<Private Sub UserForm_Initialize())

When the UserForm/ListBox code is run, I get an error
Runtime Error 380 and
<<Could not set the ListIndex Property. Invalid Property Value.

I have used this code in another project and it runs fine.
The only difference is the ListBox in the project that works
has 1 column, whereas the one that fails has 2.

Any ideas would be welcome
donwb


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Problem with ListBox, List Index

If your ListBox is MultiSelect you can't use ListIndex. See VBA help file.

"donwb" wrote:

Excel 2003
I have a 2 column, populated ListBox.
The ListBox selection routine includes the code:-
MyIndex = UserForm1.ListBox1.ListIndex
(under <<Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift
As Integer, _
ByVal X As Single, ByVal Y As Single))
and MyIndex is a Publically declared variable.

The purpose of recording the user's selection in the MyIndex variable
is so that it can be used in the UserForm Initialize process to
highlight the last selection.

The Initialize routine therefore includes the code:-
UserForm1.ListBox1.ListIndex = MyIndex
(under <<Private Sub UserForm_Initialize())

When the UserForm/ListBox code is run, I get an error
Runtime Error 380 and
<<Could not set the ListIndex Property. Invalid Property Value.

I have used this code in another project and it runs fine.
The only difference is the ListBox in the project that works
has 1 column, whereas the one that fails has 2.

Any ideas would be welcome
donwb



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Problem with ListBox, List Index

Thanks for the response.
It's in fact single select,
but my problem turned out to be wrong order of commands in my code.
donwb

"JLGWhiz" wrote in message
...
If your ListBox is MultiSelect you can't use ListIndex. See VBA help
file.

"donwb" wrote:

Excel 2003
I have a 2 column, populated ListBox.
The ListBox selection routine includes the code:-
MyIndex = UserForm1.ListBox1.ListIndex
(under <<Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal
Shift
As Integer, _
ByVal X As Single, ByVal Y As Single))
and MyIndex is a Publically declared variable.

The purpose of recording the user's selection in the MyIndex variable
is so that it can be used in the UserForm Initialize process to
highlight the last selection.

The Initialize routine therefore includes the code:-
UserForm1.ListBox1.ListIndex = MyIndex
(under <<Private Sub UserForm_Initialize())

When the UserForm/ListBox code is run, I get an error
Runtime Error 380 and
<<Could not set the ListIndex Property. Invalid Property Value.

I have used this code in another project and it runs fine.
The only difference is the ListBox in the project that works
has 1 column, whereas the one that fails has 2.

Any ideas would be welcome
donwb





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
Dependent List "Index" Problem Benjamin Excel Worksheet Functions 2 June 13th 09 05:36 PM
Problem using INDEX to select items in listbox Shazbot Excel Discussion (Misc queries) 3 April 28th 06 09:06 AM
list index problem burl_rfc Excel Programming 1 April 14th 06 03:22 AM
Listbox Index Problem Todd Huttenstine Excel Programming 3 April 26th 04 05:22 PM
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:47 PM.

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

About Us

"It's about Microsoft Excel"