我目前正在开发一个用户表单,为公司的用户创建订单以发送给我的部门。
目前我已陷入停滞状态,因为我正在努力解决以下问题。
我有一个组合框,其中包含我们业务提供的产品清单。根据选择,我希望能够添加标签和文本框,这些标签和文本框需要用户输入数据。
如果在组合框中选择此选项则 输入姓名,所需日期,用户位置等。
此外,这需要特定于组合框选择。
非常感谢任何帮助:)
更新
道歉,因为我没有任何代码用于该功能我没有添加任何这是我的代码。
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 :(得分:0)
发布问题时,您需要提供一些代码,说明您试图解决问题的位置。这是一个简短的演示,它将为您提供一个起点。
创建一个新的UserForm并在其上放置一个组合框,一个标签和一个文本框;确保它们分别命名为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
控件中,然后显示/隐藏这些框架。