在输入框中创建下拉列表

时间:2014-10-16 22:21:28

标签: excel vba

我为我们的团队创建了一个任务列表,并输入了我创建了输入框的新任务。 在"部门问题"中只能输入5个部门。 Te阻止人们输入错误的部门名称,我想使用该输入框下拉列表。

我在网上搜索过,但找不到如何在输入框中创建下拉列表。我不知道这是否可行?

任何人都可以帮助我吗?

我为输入编写的代码如下:

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

2 个答案:

答案 0 :(得分:1)

我在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

对于日期,我创建了一个单独的表单(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

Monthview1是Excel中的一个额外选项,您可以通过以下方式激活: 表单工具箱 - &gt;右键单击工具箱 - &gt;选择其他控件 - &gt; Microsoft Monthviews控件

答案 1 :(得分:0)

Type 8 的输入框可用于下拉操作。这是其中的一些代码:

>>> anArray = np.random.randint(1, 20, size=(20, 4, 4))
>>> BinaryList = np.array([1,0,0,1,1,1,0,1,1,1,0,0,0,0,1,1,1,0,0,1]).astype(bool)
>>> anArray[BinaryList].shape
(11, 4, 4)
>>> anArray[~BinaryList].shape
(9, 4, 4)

这最初是用每个单元格作为范围名称创建的。

相关问题