Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a userform with multiple comboboxes (combobox1 - combobox40)
I want to fill the combobox, preferably using .additem , so that the user can't change it. Somehow, I can't set the cboBox variable. This is what I've tried: Sub FillAllComboBoxes() dim cboBox as msforms.combobox dim frmSettings as userform frmSettings = SettingsForm ' the name of my userform With frmSettings .combobox1.additem = "FirstItem" 'works just fine set cboBox = .combobox1 ' bugs out here call FillcomboBox(cboBox) End with end sub Sub FillcomboBox(cboBox as MsForms.combobox) cboBox.additem = "value1" cboBox.additem = "value2" End sub I can't get passed the set cboBox = .combobox1 line without it bugging out. Ideally, I'd like to cycle through the combobox using their numbers. I saw this posting by Tom Ogilvy, but can't get it to work for a userform that is not part of an active worksheet. ' this declaration is important Dim cbx as MsForms.Combobox .. . . For i = 400 To myrow - 10 Step -1 With ActiveSheet.OLEObjects("ComboBox" & i) .name = "ComboBox" & i + 1 set cbx = .Object cbx.Name = "ComboBox" & i + 1 end with Next i -- |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi try this modified code, it worked for me for Combobox1 i'm using Excel 2003 Windows XP. Regards, Simon Sub FillAllComboBoxes() Dim cboBox As MsForms.ComboBox With settingsform ..ComboBox1.AddItem "FirstItem" Set cboBox = .ComboBox1 Call FillcomboBox(cboBox) End With End Sub Sub FillcomboBox(cboBox As MsForms.ComboBox) cboBox.AddItem "value1" cboBox.AddItem "value2" End Sub -- Simon Lloyd ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708 View this thread: http://www.excelforum.com/showthread...hreadid=569126 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
setting ComboBox Control font | Excel Programming | |||
Setting properties to combobox | Excel Programming | |||
Setting ComboBox ControlSource in code | Excel Programming | |||
Combobox setting | Excel Programming | |||
Setting ComboBox Value | Excel Programming |