Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox - populate with sheetnames 1

Status
Not open for further replies.

bluegnu

Technical User
Sep 12, 2001
131
GB
Hello,

I would like to populate a forms listbox with all the sheetnames in my workbook. I would also like to exclude certain sheet names from the list.

As I add sheets, I would like this to be picked up by the code and added to the listbox.

Is this possible?
 
Yes, you can use a For Each Next loop to enumerate the worksheets in the current workbook. For example:

Code:
    Dim wbs As Worksheet
    
    For Each wbs In Worksheets
        If wbs.Name <> "somesheet" Then
            Debug.Print wbs.Name
        End If
    Next

Adapt the if wbs.Name line to exclude any sheets you don't want included.
Replace the "Debug.Print" line with code to add the sheet name to your listbox.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top