vba 在输入框中创建下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26414880/
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
Create drop down list in input-box
提问by Marco
I'm creating a task list for our team, and to enter new tasks i've created input-boxes. There are only 5 departments that should be entered in the "department question" Te prevent people from entering a wrong department name, i would like to use that input-box a drop down list.
我正在为我们的团队创建一个任务列表,并输入我创建的输入框的新任务。在“部门问题”中只应输入 5 个部门,以防止人们输入错误的部门名称,我想使用该输入框作为下拉列表。
I've searched the net, but could not find how to create a drop down list in an input-box. I don't know if this is possible?
我在网上搜索过,但找不到如何在输入框中创建下拉列表。我不知道这是否可能?
Can anyone help me?
谁能帮我?
The code i wrote for the inputs are as followed:
我为输入编写的代码如下:
Private Sub Newaction_Click()
Dim content As String, date1 As Date, date2 As Date, department As String
Sheets("DO NOT DELETE").Rows("30:30").Copy
Rows("14:14").Select
Range("C14").Activate
Selection.Insert Shift:=xlDown
content = InputBox("describe the task")
Range("C14").Value = content
department = InputBox("to which department is the task assigned? ") '<-- here i want to create drop down list
Range("D14").Value = department
date1 = InputBox("when does the task start")
Range("F14").Value = date1
date2 = InputBox("when should the task be finished? ")
Range("G14").Value = date2
End Sub
回答by Marco
I have created a form in excel in stead of using input box. For the selection of department i created a combo-box with the correct departments:
我在 excel 中创建了一个表单,而不是使用输入框。为了选择部门,我创建了一个包含正确部门的组合框:
Private Sub Newaction_Click()
Sheets("DO NOT DELETE").Rows("30:30").Copy
Rows("14:14").Select
Range("C14").Activate
Selection.Insert Shift:=xlDown
Cells(14, 3) = Taskd.Value
Cells(14, 5) = ComboBox1
Unload Me
UserForm2.Show
End Sub
Private Sub UserForm_Initialize()
Taskd.Value = ""
With ComboBox1
.AddItem "Lean"
.AddItem "Maintenance"
.AddItem "Process Engineering"
.AddItem "Safety"
.AddItem "Workinstructions"
End With
End Sub
For the dates i created a separate form (userfrom2 and userform3) to enter the dates on a calander.
对于日期,我创建了一个单独的表单(userfrom2 和 userform3)来在日历上输入日期。
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
On Error Resume Next
startd = DateClicked
Cells(14, 6).Value = startd
Unload Me
UserForm3.Show
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
On Error Resume Next
endd = DateClicked
Cells(14, 7).Value = endd
Unload Me
End Sub
The Monthview1 is an extra option in Excel which you can activate via: forms toolbox --> right click on toolbox --> select Additional controls --> Microsoft Monthviews control
Monthview1 是 Excel 中的一个额外选项,您可以通过以下方式激活它:表单工具箱 --> 右键单击工具箱 --> 选择其他控件 --> Microsoft Monthviews 控件

