Problem with ListBox, List Index

D

donwb

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
 
D

donwb

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top