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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling multiple comboboxes

Status
Not open for further replies.

djburnheim

Technical User
Jan 22, 2003
71
AU
I'm trying to fill multiple comboboxes in a worksheet with the same items but am running into troubles. I've been able to do it if the comboboxes are in a userform but can not work the code when they are in a sheet. This is what I have so far.

***code***
Sub Macro1()

Dim ctrl As Control

For Each ctrl In Sheets(1)
If TypeName(ctrl) = "ComboBox" Then
ctrl.AddItem = "Yes"
ctrl.AddItem = "No"
End If
Next ctrl

End Sub
***end code***

Any suggestions?

Thanks in advance
Dave
 
Try this:

Dim Ob as OLEObject
dim ctrl As Control

For Each Ob In Sheets(1).oleobjects
set ctrl=ob.object
If TypeName(ctrl) = "ComboBox" Then
ctrl.AddItem = "Yes"
ctrl.AddItem = "No"
End If
Next Ob



Rob
[flowerface]
 
This seems to work ok:
Code:
Option Explicit
Sub SetComboBoxes()
Dim Ob As OLEObject
  For Each Ob In Sheets(1).OLEObjects
    If TypeName(Ob.Object) = "ComboBox" Then
      With Ob.Object
        .Clear
        .AddItem "Yes"
        .AddItem "No"
        .AddItem "Maybe"
        .AddItem "Fer Sure"
      End With
    End If
  Next Ob
End Sub
 
Thanks for the help. Zathras' code is working perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top