vba (Excel) 将项目添加到用户表单组合框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27950263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(Excel) Add items to Userform combo box
提问by huzzug
I currently have an Excel spreadsheet which is created to gather my sales staff's time sheet for the day. There are a few things I'd like to do:
我目前有一个 Excel 电子表格,用于收集我的销售人员当天的时间表。我想做几件事:
I have created a Userform with the required details within the form, but the items in Combo box do not show. Here's the code for it
Private Sub ComboBox1_Change() 'combobox1_list .AddItem "PRA110AC" .AddItem "RAH111AC" .AddItem "RAJ112AC" .AddItem "MAL113AC" .AddItem "Extern" End Sub
I want this data to be pooled to another sheet within the same workbook under appropriate headers. I also want this to be a hidden sheet as this is confidential.
我在表单中创建了一个包含所需详细信息的用户表单,但组合框中的项目没有显示。这是它的代码
Private Sub ComboBox1_Change() 'combobox1_list .AddItem "PRA110AC" .AddItem "RAH111AC" .AddItem "RAJ112AC" .AddItem "MAL113AC" .AddItem "Extern" End Sub
我希望将此数据集中到同一工作簿中适当标题下的另一个工作表中。我也希望这是一个隐藏的表,因为这是机密。
I am new to this so I may have messed this up, but I guess I get a chance ;)
我是新手,所以我可能搞砸了,但我想我有机会 ;)
回答by Ibby
I believe you are in the incorrect Private sub. You are using the event "Change" in the private sub "ComboBox_1." You should be using the event "Initialize" (this event starts when the userform is loaded) in the private sub "Userform" to populate your ComboBox before you see the form. Here's how it should look:
我相信你在不正确的私人潜艇。您正在使用私有子“ComboBox_1”中的事件“Change”。在您看到表单之前,您应该在私有子“用户表单”中使用事件“初始化”(此事件在加载用户表单时开始)来填充您的组合框。这是它的外观:
Private Sub Userform_Initialize()
With Combobox1
.AddItem "PRA110AC"
.AddItem "RAH111AC"
.AddItem "RAJ112AC"
.AddItem "Extern"
End With
End Sub
I hope this helps!
我希望这有帮助!