![]() |
Scrolling in a form's listbox
Hey guys, I'd really appreciate your help!
I have a listbox on a userform that gets populated with a number of "rows" based on the user's selections in a previous form. Because the listbox has ten columns and the scrollbar is waaay off to the right, I wanted to add a second scroll bar on the form, just to the left of the listbox. When the scroll bar is used, the listbox will scroll up and down. I think I've figured out how to get from the scrollbar how many rows the user wants to move up or down ... but I have no idea how to "scroll" the listbox! I've attached the code I'm using below: Private Sub ScrollBar1_Change() 'Declarations Dim iCounter As Integer 'Scroll only if listbox is not empty If frmRecordsResult.ListBox1.ListCount 0 Then 'unselect all, select chosen. For iCounter = 0 To frmRecordsResult.ListBox1.ListCount - 1 If iCounter = ScrollBar1.Value Then frmRecordsResult.ListBox1.Selected(iCounter) = True Else frmRecordsResult.ListBox1.Selected(iCounter) = False End If Next iCounter 'scroll in listbox frmRecordsResult.ListBox1.TabIndex = Application.WorksheetFunction.Max(ScrollBar1.Value , 1) - 1 frmRecordsResult.ListBox1.Selected(Application.Wor ksheetFunction.Max(ScrollBar1.Value, 1) - 1) = True 'ADD A LINE TELLING THE LISTBOX TO "SCROLL" HERE End If End Sub Thanks for any help! Chris |
Scrolling in a form's listbox
On Apr 17, 12:03 pm, cht13er wrote:
Hey guys, I'd really appreciate your help! I have a listbox on a userform that gets populated with a number of "rows" based on the user's selections in a previous form. Because the listbox has ten columns and the scrollbar is waaay off to the right, I wanted to add a second scroll bar on the form, just to the left of the listbox. When the scroll bar is used, the listbox will scroll up and down. I think I've figured out how to get from the scrollbar how many rows the user wants to move up or down ... but I have no idea how to "scroll" the listbox! I've attached the code I'm using below: Private Sub ScrollBar1_Change() 'Declarations Dim iCounter As Integer 'Scroll only if listbox is not empty If frmRecordsResult.ListBox1.ListCount 0 Then 'unselect all, select chosen. For iCounter = 0 To frmRecordsResult.ListBox1.ListCount - 1 If iCounter = ScrollBar1.Value Then frmRecordsResult.ListBox1.Selected(iCounter) = True Else frmRecordsResult.ListBox1.Selected(iCounter) = False End If Next iCounter 'scroll in listbox frmRecordsResult.ListBox1.TabIndex = Application.WorksheetFunction.Max(ScrollBar1.Value , 1) - 1 frmRecordsResult.ListBox1.Selected(Application.Wor ksheetFunction.Max(ScrollBar1.Value, 1) - 1) = True 'ADD A LINE TELLING THE LISTBOX TO "SCROLL" HERE End If End Sub Thanks for any help! Chris Anyone? |
All times are GMT +1. The time now is 12:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com