PDA

View Full Version : Position ListBox scrollbar



mferrisi
09-21-2010, 08:13 AM
Hi,

I have a listbox with a few hundred items in it. I've set up a textbox


s = TextBox1.Text

1 To Sheets(1).ListBoxes(2).ListCount
If UCase(Sheets(1).ListBoxes(2).List(i)) Like UCase(s & "*") Then
Sheets(1).ListBoxes(2).ListIndex = i
Exit Sub
End If
Next


Here, the item is selected, but the scroll bar doesn't move, so the user still has to scroll down the sheet in order to see the selection. Is there a 'TopIndex" or some similar property that makes this easy to do?

Thanks,

CharlesH
10-12-2010, 02:03 PM
Hi,

If you can use the "Control Forms" Listbox, then the following code may help.



Sub List_BoxSroll()
Dim intIndex As Integer
txtSearch = 1
On Error Resume Next
ListBox1.Value = txtSearch ' select match

ListBox1.TopIndex = ListBox1.ListIndex ' make it scroll to top
End Sub