This is my first post on this forum. I have a quick question regarding VBA, Userforms with a listbox. 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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.