2017-11-11 461 views
0

我目前正在制定一個用戶窗體來創建一個公司用戶發送到我的部門的訂單。如何添加一個標籤和文本框基於在excel中的用戶窗體上的組合框選擇

目前我陷入了僵局,因爲我正在努力解決以下問題。

我有一個組合框,它有我們業務提供的產品列表。基於選擇,我希望能夠添加要求用戶輸入數據的標籤和文本框。

如果選擇在組合框中,然後 輸入名稱,要求的日期,用戶等位置

而且這需要具體到組合框的選擇。

任何幫助,將不勝感激:)

UPDATE

道歉,因爲我沒有該功能我沒加任何這裏是我的代碼有任何代碼。

Private Sub CommandButton1_Click() 
Windows("RFS User Form Mock.xlsm").Visible = True 
End Sub 

Private Sub LegendDefinition_Change() 
LegendDefinition.Locked = True 
End Sub 

Private Sub RequestList_Change() 
Dim i As Long, LastRow As Long 
    LastRow = Sheets("Definition").Range("A" & Rows.Count).End(xlUp).Row 
    For i = 2 To LastRow 
    If Sheets("Definition").Cells(i, "A").Value = (Me.RequestList) Then 
    Me.DefinitionBox = Sheets("Definition").Cells(i, "B").Value 
    End If 
    Next 
End Sub 

Private Sub RequestList_DropButtonClick() 
Dim i As Long, LastRow As Long 
    LastRow = Sheets("Definition").Range("A" & Rows.Count).End(xlUp).Row 
    If Me.RequestList.ListCount = 0 Then 
    For i = 2 To LastRow 
    Me.RequestList.AddItem Sheets("Definition").Cells(i, "A").Value 
    Next i 
    End If 
End Sub 

Sub UserForm_Initialize() 
    SiteList.List = Array("Birmingham", "Bristol", "Cardiff", "Chelmsford", "Edinburgh", "Fenchurch Street", "Glasgow", "Guernsey", "Halifax", "Homeworker", "Horsham", "Ipswich", "Jersey", "Leeds", "Leicester", "Lennox Wood", "Liverpool", "Manchester", "Peterborough", "Redhill", "Sunderland", "Madrid") 
End Sub 

Private Sub VLookUp_Change() 
VLookUp.Locked = True 
End Sub 

回答

0

發佈問題時,您需要提供一些代碼,顯示您正在嘗試解決問題的位置。不過這是一個簡短的演示,它會給你一個起點。

創建一個新的用戶窗體並在其上放置組合框,標籤和文本框;確保它們分別命名爲ComboBox1,Label1和TextBox1。

然後,粘貼此代碼的形式的模塊:

Option Explicit 

Private Sub ComboBox1_Change() 
    Dim bVisible As Boolean 

    'Only show the label and the textbox when the combo list index is 1, which corresponds to "Item 2". 
    'Note: bVisible = (ComboBox1.Text = "Item 2") would also work. 
    bVisible = (ComboBox1.ListIndex = 1) 
    Label1.Visible = bVisible 
    TextBox1.Visible = bVisible 
End Sub 

Private Sub UserForm_Layout() 
    'Populate the combo. 
    ComboBox1.AddItem "Item 1", 0 
    ComboBox1.AddItem "Item 2", 1 

    'Note: the code below could be removed by setting the corresponding 
    'design-time properties from the form designer. 
    ComboBox1.Style = fmStyleDropDownList 
    Label1.Visible = False 
    TextBox1.Visible = False 
End Sub 

然後按F5顯示形式。您會注意到標籤和文本框僅在組合顯示「項目2」時纔可見。可見性調整在ComboBox1_Change事件處理程序中執行。

如果您打算根據組合的值顯示/隱藏多個控件,您可以將它們分組爲一個或多個Frame控件,並顯示/隱藏這些框架。

+0

代碼是否添加了幫助?我會把用戶界面的圖像,但我沒有足夠的代表。此外,我正在使用VLookup與相同的組合框。該組合框稱爲RequestList。 –

相關問題