简体   繁体   English

Excel VBA用户窗体-如何从用户窗体中的列表向组合框添加值?

[英]Excel VBA Userform - How do I add a value to a combo box from a list in the userform?

Is there a way to do the following:? 有没有办法做到以下几点?

I would like a manual text box that when filled in and the user clicks "Add" and it adds the value to the combo box. 我想要一个手动文本框,当填写该框时,用户单击“添加”,它会将值添加到组合框。 However, I will also have this list stored somewhere so that the next time the user loads the form they can select "Previously Used" items from a list and these will then also be added to the combo box. 但是,我还将这个列表存储在某个地方,以便下次用户加载表单时,他们可以从列表中选择“以前使用”的项目,然后这些项目也将添加到组合框中。

I will be adding a button to "Add all" of the previous items but it must still have the option to add items manually each time. 我将在“添加所有”以前的项目中添加一个按钮,但它仍必须具有每次手动添加项目的选项。

Even more useful would be to have an option to check items in and out of the combo box as well as the manually text input option. 更加有用的是,可以使用一个选项来检查组合框内和外的项目以及手动文本输入选项。

I tried to add an image I found to better explain this but I need 10 rep points. 我尝试添加一张图片,以更好地解释这一点,但我需要10个代表点。 Therefore, I hope this makes sense but please feel free to comment for more details and a better explanation if needed. 因此,我希望这是有道理的,但如有需要,请随时发表评论以获取更多详细信息和更好的解释。

Link to an example of what I am thinking of but without the manual addition field: 链接到我正在考虑的示例,但没有手动添加字段:

http://kb.blackboard.com/download/attachments/14057766/bbui_multi_select.gif?version=1&modificationDate=1202823953747 http://kb.blackboard.com/download/attachments/14057766/bbui_multi_select.gif?version=1&modificationDate=1202823953747

Use this 用这个

combobox1.additem txtValue.Text

Sheets("SheetName").Cells(lastRow+1,col).value=txtValue.Text

Also add below code in Form_activate 还要在Form_activate中添加以下代码

For i=1 to lastrow
combobox1.additem Sheets("SheetName").Cells(i,col).value

next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM