[英]Userforms with a listbox in VBA
This is my first post on this forum.这是我在这个论坛上的第一篇文章。 I have a quick question regarding VBA, Userforms with a listbox.我有一个关于 VBA,带列表框的用户表单的快速问题。 My goal is to select two options and return a list of names in a listbox.我的目标是选择两个选项并在列表框中返回名称列表。 I have attached the example userform and the example table that I would be choosing from.我附上了示例用户表单和我将从中选择的示例表。 Any help would be appreciated.任何帮助,将不胜感激。
Current VBA for Userform用户表单的当前 VBA
Private Sub ListBox1_Click()
Sheets("Trainers1").Range("I2") = ListBox1
End Sub
Private Sub ListBox2_Click()
Sheets("Trainers1").Range("I2") = ListBox2
End Sub
Private Sub ListBox3_Click()
Sheets("Trainers1").Range("I3") = ListBox3
End Sub
Private Sub ListBox4_Change()
.ListBox4 = Sheets("Trainers1").Range("K2:K10")
End Sub
Private Sub UserForm_Initialize()
Dim cnt
Dim cntr As Integer
cntr = Application.WorksheetFunction.CountA(Sheets("Shift Pattern Key").Range("A:A"))
cnt = Application.WorksheetFunction.CountA(Sheets("Training Ratio").Range("A:A"))
For i = 2 To cntr
ListBox2.AddItem Sheets("Shift Pattern Key").Cells(i, 1)
Next i
For i2 = 2 To cnt
ListBox3.AddItem Sheets("Training Ratio").Cells(i2, 1)
Next i2
End Sub
You could iterate through the rows of your table and compare the values in each row to the values selected.您可以遍历表的行并将每行中的值与选定的值进行比较。 If both values in a row match the values selected by the user you can then use the .AddItem method to add the name of the employee to the list.如果一行中的两个值都与用户选择的值匹配,则可以使用 .AddItem 方法将员工姓名添加到列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.