troubleshooting Question

How do I add items to a ListBox in Excel VBA when the workbook first opens

Avatar of Tocogroup
TocogroupFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft Excel
7 Comments1 Solution1884 ViewsLast Modified:
Hi,

This relates to a previous Excel VBA Active X ListBox question resolved by EE expert dlmille.

I have a 'Menu' worksheet which, when activated, adds items to a ListBox. It works fine when I click on the 'Menu' worksheet tab from another sheet, but when I first open the workbook and it defaults to the 'Menu' worksheet the ListBox is empty. I have to move to another sheet, and then back to the 'Menu' sheet to add the list items.

Is there any way I can display the list items when the workbook first opens without having to display another sheet and then move back to the 'Menu' sheet ?

Also, can I display the first list item as the default selected item, as all the items are unselected when they are first displayed. I've attached the code to show you the procedure.

Thanks
Toco
Private Sub Worksheet_Activate()
   ListBox1.Clear
   For Row = 2 to 20
      ListBox1.AddItem Sheets("Tables").Cells(Row,10).Value
   Next Row
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros