Announcement

Collapse
No announcement yet.

VBA : Adding Items to ActiveX ComboBox?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA : Adding Items to ActiveX ComboBox?



    Does anyone in here know how to add items to a combobox? I have a couple of macros written and ready to go but, I am not to familiar with ActiveX. After I have entered the terms how do I link the macros to run on the selected item?

  • #2


    Welcome to the forum!

    This is one way to load a combobox if your data is in a range of cells when the form is first activated and also how you can run a procedure based on the ListIndex of the combobox

    Private Sub ComboBox1_Change()
    Select Case ComboBox1.ListIndex
    Case 0
    Run (mymacro)
    Case 1
    Run (yourmacro)
    End Select
    End Sub

    Private Sub UserForm_Activate()
    Dim i As Integer
    For i = 1 To Range(Range("A1"), Range("A1").End(xlDown)).Count
    ComboBox1.AddItem Range("A1").Offset(i - 1, 0).Value

    Next i

    End Sub

    You could also store your items you want to add in an Array and loop through the array to add the items. I am using a form in the VBE to do the above procedures.

    HTH

    Bruce

    Comment

    Working...
    X