how to populate a combobox with tab names

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
In my workbook I have tabs named Hats, Shirts, Pants and Shoes. Within each tabs, there is a list of the various types of clothing. For example, if hat is selected there is a list of various types of hats located in the sheet with the tab labeled hats that will populate another combobox. I found some code that displays all the tabs in a messagebox.
Code:
[COLOR=#000000][FONT=Consolas]Sub WorksheetLoop()[/FONT][/COLOR]<code class="" style="box-sizing: inherit; font-family: Consolas, "Courier New", Courier, monospace; font-size: 1em;">
         Dim WS_Count As Integer
         Dim I As Integer

         ' Set WS_Count equal to the number of worksheets in the active
         ' workbook.
         WS_Count = ActiveWorkbook.Worksheets.Count

         ' Begin the loop.
         For I = 1 To WS_Count

            ' Insert your code here.
            ' The following line shows how to reference a sheet within
            ' the loop by displaying the worksheet name in a dialog box.
            MsgBox ActiveWorkbook.Worksheets(I).Name

         Next I

</code>[COLOR=#000000][FONT=Consolas]      End Sub[/FONT][/COLOR]
But I would like to display them in a combo box instead of a message box. So I tried this instead.
Code:
Private Sub cmbClothingLine_Enter()    Dim WS_Count As Integer
    Dim I As Integer
        
    cmbClothingLine.Clear
        
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    
        For I = 5 To WS_Count
            With cmbClothingLine
                ActiveWorkbook.Worksheets(I).Name
                .AddItem
            End With
        Next I
   
End Sub
I then get a "Run-time error: '438': Object doesn't support this property or method" How can I fix this. Thank You.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Put this script in a Command button:

Code:
Private Sub CommandButton1_Click()
'Modified 6/25/18 12:10 AM EDT
Dim i As Long
cmbClothingLine.Clear
    For i = 1 To Sheets.Count
        cmbClothingLine.AddItem Sheets(i).Name
    Next
End Sub
 
Upvote 0
If you wanted to see them in a Message Box. I would do it this way:
Code:
Private Sub CommandButton2_Click()
'Modified 6/25/18 12:25 AM EDT
Dim i As Long
Dim ans As String
Dim anss As String
    For i = Sheets.Count To 1 Step -1
        ans = Sheets(i).Name & vbNewLine & ans
    Next
anss = "Your sheet names are:" & vbNewLine
MsgBox anss & ans
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top