Consulting

Results 1 to 3 of 3

Thread: Populate Combobox with Worksheet Names EXCLUDE hidden

  1. #1

    Populate Combobox with Worksheet Names EXCLUDE hidden

    Hi

    I have a code that shows all the sheet names in a workbook. How do I exclude the hidden sheets from the combobox list?

    Private Sub Userform_Initialize()
    Dim sht As Worksheet, txt As String
    
    For Each sht In ActiveWorkbook.Sheets
        Me.ComboBox1.AddItem sht.Name
    
    Next sht
    End Sub

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    Try
    Private Sub Userform_Initialize() 
        Dim sht As Worksheet, txt As String 
         
        For Each sht In ActiveWorkbook.Sheets
            If sht.Visible = xlSheetVisible Then
                Me.ComboBox1.AddItem sht.Name 
            End If     
        Next sht 
    End Sub

  3. #3
    Knowledge Base Approver VBAX Guru
    Joined
    Apr 2012
    Posts
    4,746
    Private Sub Userform_Initialize() 
      For Each sh In Sheets 
         if sh.visible then c00=c00 & "|" & sh.name 
      Next
    
      Combobox1.list=split(mid(c00,2),"|")
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •