Reputation: 11
I want to add item to a combobox found in excel worksheet from text box which is located in the user form When button is clicked.i see the value added to combobox but it will become empty when I close and reopens the workbook.can any one help me handling this?
Thank u for you're fast response first
thank you both for your feedback and correction.let me make more clear my concern
Upvotes: 0
Views: 1516
Reputation: 761
dn_cmb_items
Range: =""
dn_cmb_items
frm_add_cmb_item
and set ShowModal
to False
.tb_item_text
.cmb_add
and from its context menu choose View code
. This creates the click
event handler.Private Sub cmb_add_Click() Dim v_r As Range, v_n As Name Set v_n = Names("dn_cmb_items") If v_n.Value = "=""""" Then v_n.Value = "=" & Worksheets(1).Name & "!$A$1:$A$1" v_n.RefersToRange.Value = tb_item_text.Text Else Set v_r = v_n.RefersToRange Set v_r = v_r.Cells(v_r.Rows.Count + 1, 1) v_r.Value = tb_item_text.Text v_n.Value = "=" & Worksheets(1).Name & "!$A$1:" & v_r.Address(True, True) End If End Sub
frm_add_cmb_item.Show
.Debug
menu choose Compile
. Then save the VBAProject as well as the workbook. That's all for the coding.cmb_add
button, a new item will be added to the A
column at the end thus changing the value of dn_cmb_items
assigned to the combobox on the worksheet.
See the screenshorts attached:Initial state:
1
added:
2
added:
PS I have the ready workbook with all the code. Where should I upload it?
Upvotes: 1
Reputation: 475
Be specific with your question and always post the relevant code, so that it will become easy to solve it for others.
If you want to see the data while executing the userform, just write the required data in userform_activate or Initialize. before executing it will take the values and shows up in the combobox.
the input which you are taking from the worksheet just write those values in another worksheet so that whenever you open the workbook the values will not get erased.
Upvotes: 0