Search code examples
vbacomboboxms-worduserform

Is there a way to add to a combobox list using a textbox and button?


I'm looking for a way to add items to a combobox list without adding the item to the code directly.

UserForm Image

Private Sub UserForm_Initialize()
    With ComboBox2
         .AddItem ".020"
         .AddItem ".030"
         .AddItem ".032"
         .AddItem ".040"
   End With

   With ComboBox3
        .AddItem "THK"
        .AddItem "DIA"
        .AddItem "TUBE"
        .AddItem "FORGING"
    End With
End Sub

I'd like the user to be able to add an Item into the dropdown list without going into the code. Is there a way to add an .AddItem to the combobox?


Solution

  • Unlike ListBoxes, ComboBoxes allow a user to type a new entry directly into the comboBox field. That's the simplest solution, no extra code required!

    If, for some reason, you want to make this more complicated, you can add a text field and a command button. After the user types a new entry in the text field, they click on the button which runs this macro:

    Private Sub CommandButton1_Click()
      ComboBox3.AddItem TextBox1.value
    End Sub