ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Update Combobox with New Data (https://www.excelbanter.com/excel-programming/300267-re-update-combobox-new-data.html)

keepITcool

Update Combobox with New Data
 

this isn't perfect but should give you a start

you may add:
sorting, checking that item is not in list etc etc.



Option Explicit
Dim prEvent As Boolean

Private Sub cboBox1_change()
If prEvent Then Exit Sub
If cboBox1.ListIndex = cboBox1.ListCount - 1 Then
txtBox1.SetFocus
End If
End Sub

Private Sub txtBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If prEvent Then Exit Sub Else prEvent = True

If txtBox1.Text < "" Then
If MsgBox("Add this to combo?", vbYesNo) = vbYes Then
cboBox1.AddItem txtBox1.Text, cboBox1.ListCount - 1
End If
txtBox1.Text = ""

End If
cboBox1.ListIndex = cboBox1.ListCount - 2
cboBox1.SetFocus
prEvent = False

End Sub

Private Sub UserForm_Initialize()
prEvent = True
With Me.cboBox1
'some props that should be set in design
.MatchEntry = fmMatchEntryFirstLetter
.MatchRequired = True
.Style = fmStyleDropDownList
'add a few items
.AddItem "Choice1"
.AddItem "Choice2"
.AddItem "AddNewItem"
.ListIndex = 0
End With
prEvent = False
End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?VHJveQ==?=" wrote:

Can anyone help me with this problem?

Userform with a ComboBox:
Top line in list is "Add New Data"

When line is selected, another Userform is opened, it has:
A label asking for new data
A Textbox
A Commandbutton

When the Commandbutton is pressed:
The value of the Textbox is added to the Combobox.
The value of the Combobox is the new data added.

Is all this possible?

Thanks...




All times are GMT +1. The time now is 03:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com