2014-10-16 44 views
0

我爲我們的團隊創建任務列表,並輸入創建輸入框的新任務。 在「部門問題」中只應輸入5個部門 爲防止人們輸入錯誤的部門名稱,我希望使用該輸入框的下拉列表。在輸入框中創建下拉列表

我搜索了網絡,但無法找到如何在輸入框中創建一個下拉列表。我不知道這是否可能?

任何人都可以幫助我嗎?

我寫爲輸入的碼是如下:

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 

回答

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中多了一種選擇,你可以通過激活: 形式工具箱 - >右鍵單擊工具箱 - >選擇附加控制 - >微軟Monthviews控制