Learn Macros‎ > ‎VBA Macros‎ > ‎

Navigation into Worksheets using Listbox

posted Jan 30, 2011, 5:24 AM by Ayush Jain   [ updated Jan 30, 2011, 5:29 AM by ayushjain@live.com ]
To navigate into your excel sheets using Listbox, You need to add a ListBox in a UserForm and copy this two simple procedures in the Userform Code:

Private Sub ListBox1_Click()
    Sheets(ListBox1.ListIndex + 1).Activate
End Sub

Private Sub UserForm_Initialize()
    Dim sht As Worksheet
    For Each sht In ActiveWorkbook.Worksheets
        ListBox1.AddItem sht.Name
    Next sht
End Sub

Once you show the UserForm it will add the names of the sheets in the ListBox, then when you click on one of the sheets name in the ListBox it will activate the corresponding sheet in the WorkBook.

Comments