|
-
Mar 21st, 2006, 03:50 AM
#1
Thread Starter
Frenzied Member
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 ?
Last edited by TheBionicOrange; Mar 22nd, 2006 at 11:43 AM.
-
Mar 22nd, 2006, 11:34 AM
#2
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
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 22nd, 2006, 11:43 AM
#3
Thread Starter
Frenzied Member
Re: Setting Combox values using "For Each" statement ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|