View Single Post
  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Greg_Maxey via OfficeKB.com Greg_Maxey via OfficeKB.com is offline
external usenet poster
 
Posts: 1
Default Looping UserForm ComboBox

Graham's answer is will do the job quite well in this case. There are a few
other techniques that you might put in your toolbox for cases where the
number of controls involved is large:

The first loops through like named controls with an index number:

Private MonthArray As Variant
Private Sub UserForm_Initialize()
Dim i As Long
Dim CtrNameArray As String
CtrNameArray = Split("ComboBox1|ComboBox1|ComboBox1|ComboBox1|Com boBox1")
MonthArray = Split("01|02|03|04|05|06|07|08|09|10|11|12|", "|")
For i = 1 To 5 'or to whatever number you need.
Me.Controls("ComboBox" & i).List = MonthArray
Next i
End Sub

The other uses a second array to provide uniquely named controls to the loop:

Private Sub UserForm_Initialize()
Dim i As Long
Dim CtrNameArray() As String 'Variant
CtrNameArray = Split
("ComboBoxAlpha|ComboBoxBravo|ComboBoxCharlie|Comb oBoxDelta|ComboBoxEcho",
"|")
MonthArray = Split("01|02|03|04|05|06|07|08|09|10|11|12|", "|")
For i = 0 To UBound(CtrNameArray)
Me.Controls(CtrNameArray(i)).List = MonthArray
Next i
End Sub



Owen wrote:
Hi

I would like to use the code below in a loop so that i can populate numerous
ComboBoxes within my UserForm with the same list.

I am not sure how to go about this, and would appreciate any help.

Thanks

With ComboBox7
Dim MonthArray As Variant
MonthArray = Split("01|02|03|04|05|06|07|08|09|10|11|12|", "|")
ComboBox7.List = MonthArray
End With


--
Greg Maxey

Please visit my web site http://gregmaxey.mvps.org

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ement/201006/1