title: Adding items to a ComboBox that is added to userform during run time
body: <p>I am trying to add a combo box to a user form which will be created at run time , the problem I am facing is to add items to the combo box? Not able to figure out where the mistake would be. Thanks.</p>
  
  <pre><code>    Function addComboBox(ByRef TempForm As Object, ByVal controlType As String, 
  ByVal pos As Integer, ByVal strCaption As String, ByVal strValues As String)
  
       Dim NewComboBox As MSforms.ComboBox
       Dim arr As Variant
       Dim i As Integer
  
       Set NewComboBox = TempForm.Designer.Controls.Add("forms.ComboBox.1")
        arr = Split(strValues, ";")
  
  
          With NewComboBox
                  .Name = strCaption &amp; "_" &amp; controlType &amp; "_" &amp; pos
                  .Top = 20 + (12 * pos)
                  .Left = 100
                  .Width = 150
                  .Height = 12
  
          End With
  
  
  
        For i = 0 To UBound(arr)
  
         NewComboBox.AddItem arr(i)
  
        Next i
  
      End Function
  </code></pre>