[英]how to add item to a combobox on button click?
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? 我想将项目添加到从用户窗体中位于文本框中的excel工作表中找到的组合框中。单击按钮时。我看到添加到组合框中的值,但是当我关闭并重新打开工作簿时它将变为空。可以是任何一个帮我处理这个吗?
Thank u for you're fast response first 谢谢您的快速回复
thank you both for your feedback and correction.let me make more clear my concern 感谢您的反馈和指正。让我更清楚地表达我的关注
dn_cmb_items
Range: =""
dn_cmb_items
范围: =""
dn_cmb_items
dn_cmb_items
frm_add_cmb_item
and set ShowModal
to False
. frm_add_cmb_item
并将ShowModal
设置为False
。 tb_item_text
. tb_item_text
。 cmb_add
and from its context menu choose View code
. cmb_add
,然后从其上下文菜单中选择View code
。 This creates the click
event handler. click
事件处理程序。 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
. frm_add_cmb_item.Show
实现创建的宏。 Debug
menu choose Compile
. Debug
菜单中,选择“ Compile
。 Then save the VBAProject as well as the workbook. 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. cmb_add
按钮时,新项目将添加到末尾的A
列中,从而更改分配给工作表上组合框的dn_cmb_items
的值。 See the screenshorts attached: Initial state: 初始状态:
1
added: 添加了
1
:
2
added: 2
添加:
PS I have the ready workbook with all the code. PS我已经准备好所有代码的工作簿。 Where should I upload it?
我应该在哪里上传?
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. 如果要在执行用户窗体时查看数据,只需将所需的数据写入userform_activate或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. 您从工作表中获取的输入只需将这些值写入另一个工作表中,这样无论何时打开工作簿,这些值都不会被擦除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.