View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Populate a combo box

Can you try to add it when the user moves off the combobox?

Option Explicit
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Resp As Long
With Me.ComboBox1
If .Value = "" Then
'do nothing
Else
If .ListIndex = -1 Then
Resp = MsgBox(Prompt:="do you want to add: " & .Value, _
Buttons:=vbYesNo)
If Resp = vbYes Then
.AddItem .Value
Else
'leave the combobox or stay in it?????
'Cancel = True
End If
End If
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ComboBox1
.Style = fmStyleDropDownCombo
For iCtr = 1 To 4
.AddItem "A" & iCtr
Next iCtr
End With
End Sub


damorrison wrote:

I am using the add item way to populate a combobox in a userform

Private Sub Userform_Initialize()
With Me.ComboBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem ""

End With
End Sub

How does one add an Item when the user types in a name that is not in
the list


--

Dave Peterson