Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Scroll Issue 1

Status
Not open for further replies.

TopJack

Programmer
Mar 10, 2001
153
GB
This is driving me mad, any help would be appreciated.

I have a listbox (multi select) on a userform in Excel 2003. The userform is presented to the user with a quick find facility to save the user scrolling through the listbox if he wants. I can make the find facility select the item in the listbox no problem using this code :-

Code:
Private Sub find_item_Click()
Dim item As String, counter As Long

item = InputBox("Please enter your item number")

With Menu
    counter = 0
    For Each lname In .ListBox3.List
        If (lname = item) Then
            .ListBox3.Selected(counter) = True
            Exit Sub
        End If
        counter = counter + 1
    Next lname
End With

End Sub

The problem is the listbox does not scroll to the newly selected item to show the user it has been found.

How can I force the listbox to scroll aswell as select the item the user wants.

I was thinking I could set the value which might do the job but I get an error message
Code:
.ListBox3.Value = .ListBox3.List(counter)

"Runtime error 380: Could not set the value property. Invalid property value"

Any clues?
 

Try putting
Code:
   .ListBox3.ListIndex = counter
before the Exit Sub

 
Top notch Zathras. Works exactly how I wanted.

Star on its way ....... Thanks.
 
TopJack
It can be done in much more effective way by replacing it with Combobox, no code will be required, and the search will avoid the loop meaning it will be as fast as it can be. Just set:

ComboBox1.MatchEntry = fmMatchEntryComplete
ComboBox1.Style = fmStyleDropDownList

vladconn
 

vlad, if you re-read the original post you will see that TopJack specified a multi-select list box. A combo box just won't cut it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top