Setting Combox values using "For Each" statement ...
I've got a form in Excel that contains 20+ comboboxes.
Unfortunately I can't use control arrays, but rather than setting the rowsource for each combobox in turn I am trying to do the following :
VB Code:
Dim cbo As ComboBox
For Each cbo In [B]forms[/B]
cbo.RowSource = "'Data Source'!P3:P4"
Next
For some reason this doesn't work ?!?!
The "forms" object seems empty ?!!
Do I have to address it as something else in VBA ?
Re: Setting Combox values using "For Each" statement ...
BO
Are you trying to set the rowsource in the UserForm_Initialize event? If so, then you need to use the Controls collection of the Form to loop through the comboboxes.
Here's some sample code. Note: I am assuming that each combobox has a name that begins with "cbo".
VB Code:
Private Sub UserForm_Initialize()
Dim MyCombo As Control
For Each MyCombo In Me.Controls
If Left(MyCombo.Name, 3) = "cbo" Then
MyCombo.RowSource = "'Data Source'!P3:P4"
End If
Next
End Sub
Re: Setting Combox values using "For Each" statement ...