Combo Box - Drop Down Box

     

     

  • Add Combobox Programtically
  •  

  • We can use OLEOBJECTS.Add method
  •  

    Add COMBOBOX programtically

     

    Private Sub CommandButton1_Click()
    Dim cb As OLEObject
    On Error Resume Next
    Set cb = ActiveSheet.OLEObjects.Add _
    (classtype:="Forms.combobox.1", Link:=False _
    , displayasicon:=False)
    With cb
    .Name = "myname"
    .Left = Columns("B:E").Left
    .Width = Columns("B:E").Width
    .Height = Rows("10:11").Height
    .Top = Rows("10:11").Top
    .ListFillRange = "Sheet2!A1:A11"
    End With
    End Sub

     

    Download the Workbook

     

     

  • Combo Box works like a drop down box
  •  

  • It consists of list of items in drop-down box and enables the use to see only one item at a time
  •  

  • List values are visible by using dropdown only
  •  

    ADD Item: Syntax

     

     

  • Item indicates it adds one item per each row
  •  

  • Index indicates position of item, in the list
  •  

    Additem to combo box:

     

     

     

    Additem to combo box - With:

     

     

     

    Additem to combo box - Range:

     

     

    Additem to combo box - Named Range:

     

     

  • Define the Name
  •  

     

  • Mention the Name in LISTFILL RANGE FIELD
  •  

     

    Download the Workbook

     

     

    Combo Box - Add & Delete values

     

    Private Sub CommandButton1_Click()
    Dim i As Integer
    For i = 1 To 11
    ComboBox1.AddItem i
    Next
    End Sub
    'Clear Values in combo box
    Private Sub CommandButton2_Click()
    ComboBox1.Clear
    End Sub

     

    Download the Workbook

     

    Combo Box - ADD ARRAY values

     

    Private Sub CommandButton1_Click()
    Dim cb As OLEObject
    Set cb = ActiveSheet.OLEObjects.Add(classtype:="Forms.combobox.1", Link:=False _
    , displayasicon:=False)
    With cb
    .Name = "myname"
    .Left = Columns("B:E").Left
    .Width = Columns("B:E").Width
    .Height = Rows("10:11").Height
    .Top = Rows("10:11").Top
    End With
    cb.Object.List = Array("a", "b", "c", "d", "f")
    End Sub

    Download the Workbook

     

     

     

     

    Add Data to combobox in Userform

     

     

    Download the Workbook

     

    Combo Box - Userform

     

     

    Download the Workbook

     

    Combo Box - Click event

     

    Private Sub ComboBox1_Click()
    If ComboBox1.Value = 5 Then
    Exit Sub
    End If
    End Sub