' ensure that a listbox item is visible' if the second argument is omitted, the index of current item is used'' NOTE: uses the ListBoxVisibleItems functionSub ListBoxEnsureVisible(lst As ListBox, Optional ByVal itemIndex As Long = -1) Dim visibleCount As Long ' provide a default for the 2nd argument If itemIndex < 0 Then itemIndex = lst.ListIndex ' get the number of visible items visibleCount = ListBoxVisibleItems(lst) If itemIndex < lst.TopIndex Then ' scroll up lst.TopIndex = itemIndex ElseIf itemIndex >= lst.TopIndex + visibleCount Then ' scroll down lst.TopIndex = itemIndex - visibleCount + 1 End If End Sub
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.























