![]() |
ListBox Scrolling in VBA
Greetings!
In Excel 2000 I am using a ListBox on a UserForm to display the progress of a lengthy procedure to the end user. As tasks are completed, I call the ListBox.AddItem method to add items to the end of the list. The problem is that the list soon becomes longer than what the ListBox viewable area can accommodate. When this happens, Windows dutifully provides a scrollbar for the user to scroll down to see subsequently added lines. My question is: How can I make it scroll programatically so that the last item in the list is always visible? I have searched and searched but cannot seem to find the answer. Common sense (a dangerous thing) tells me that the solution can't be as allusive as it seems. If anyone knows how to do this, please let me know. Thanks In Advance! -- Kevin |
ListBox Scrolling in VBA
Kevin
Add this after your AddItem line Me.ListBox1.TopIndex = Me.Listbox1.ListCount - 1 -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Kevin" wrote in message ... Greetings! In Excel 2000 I am using a ListBox on a UserForm to display the progress of a lengthy procedure to the end user. As tasks are completed, I call the ListBox.AddItem method to add items to the end of the list. The problem is that the list soon becomes longer than what the ListBox viewable area can accommodate. When this happens, Windows dutifully provides a scrollbar for the user to scroll down to see subsequently added lines. My question is: How can I make it scroll programatically so that the last item in the list is always visible? I have searched and searched but cannot seem to find the answer. Common sense (a dangerous thing) tells me that the solution can't be as allusive as it seems. If anyone knows how to do this, please let me know. Thanks In Advance! -- Kevin |
ListBox Scrolling in VBA
dim index as long
after you add your items set the index to the listcount property then set the list's listindex to this... mylist.add something index = mylist.listcount-1 '' zero based ! mylist.listindex = index -- Patrick Molloy Microsoft Excel MVP --------------------------------- I Feel Great! --------------------------------- "Kevin" wrote in message ... Greetings! In Excel 2000 I am using a ListBox on a UserForm to display the progress of a lengthy procedure to the end user. As tasks are completed, I call the ListBox.AddItem method to add items to the end of the list. The problem is that the list soon becomes longer than what the ListBox viewable area can accommodate. When this happens, Windows dutifully provides a scrollbar for the user to scroll down to see subsequently added lines. My question is: How can I make it scroll programatically so that the last item in the list is always visible? I have searched and searched but cannot seem to find the answer. Common sense (a dangerous thing) tells me that the solution can't be as allusive as it seems. If anyone knows how to do this, please let me know. Thanks In Advance! -- Kevin |
ListBox Scrolling in VBA
Thanks for your help!
-- Kevin "Dick Kusleika" wrote: Kevin Add this after your AddItem line Me.ListBox1.TopIndex = Me.Listbox1.ListCount - 1 -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Kevin" wrote in message ... Greetings! In Excel 2000 I am using a ListBox on a UserForm to display the progress of a lengthy procedure to the end user. As tasks are completed, I call the ListBox.AddItem method to add items to the end of the list. The problem is that the list soon becomes longer than what the ListBox viewable area can accommodate. When this happens, Windows dutifully provides a scrollbar for the user to scroll down to see subsequently added lines. My question is: How can I make it scroll programatically so that the last item in the list is always visible? I have searched and searched but cannot seem to find the answer. Common sense (a dangerous thing) tells me that the solution can't be as allusive as it seems. If anyone knows how to do this, please let me know. Thanks In Advance! -- Kevin |
ListBox Scrolling in VBA
Thanks for your help!
-- Kevin "Patrick Molloy" wrote: dim index as long after you add your items set the index to the listcount property then set the list's listindex to this... mylist.add something index = mylist.listcount-1 '' zero based ! mylist.listindex = index -- Patrick Molloy Microsoft Excel MVP --------------------------------- I Feel Great! --------------------------------- "Kevin" wrote in message ... Greetings! In Excel 2000 I am using a ListBox on a UserForm to display the progress of a lengthy procedure to the end user. As tasks are completed, I call the ListBox.AddItem method to add items to the end of the list. The problem is that the list soon becomes longer than what the ListBox viewable area can accommodate. When this happens, Windows dutifully provides a scrollbar for the user to scroll down to see subsequently added lines. My question is: How can I make it scroll programatically so that the last item in the list is always visible? I have searched and searched but cannot seem to find the answer. Common sense (a dangerous thing) tells me that the solution can't be as allusive as it seems. If anyone knows how to do this, please let me know. Thanks In Advance! -- Kevin |
All times are GMT +1. The time now is 08:07 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com