View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Williams[_4_] John Williams[_4_] is offline
external usenet poster
 
Posts: 12
Default Dynamically adding data to a Combobox?

samanathon wrote in message ...
Hi All!

For my first post . . . I NEED HELP!

I would like for a user to be able to click a button, a userform opens
and the user can input data. This new data will be added to a
combobox.

I have the userform and botton covered. I need help with the dynamic
code for adding new data to the combobox!


Assuming your userform has TextBox1 and ComboBox1 on it, the following
code in the userform should do what you want:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)

If KeyCode = vbKeyReturn Then
KeyCode = 0

ComboBox1.AddItem TextBox1.Text
ComboBox1.ListIndex = 0

TextBox1.Text = ""
TextBox1.SetFocus

End If

End Sub