Question

1 of the UserForms(UserForm1) has a ListBox(ListBox1) and in this ListBox, there are 3 items, when i double click on the first item, it goes to UserForm2, when i double click on the second item, it goes to UserForm3, and when i double click on the 3 item, it goes to UserForm4.

Was it helpful?

Solution

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    Dim Obj As Object
    Set Obj = VBA.UserForms.Add("UserForm" & CStr(ListBox1.ListIndex + 2))
    Obj.Show
    Unload Obj

End Sub

See http://www.cpearson.com/Excel/showanyform.htm

OTHER TIPS

These codes can be used (When any item of listbox clicked,another userform opens. The opened userform's text boxes are populated based on listbox clicked item value):

Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Load UserForm2
UserForm2.TextBox1 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 0)
UserForm2.TextBox2 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 1)
UserForm2.TextBox3 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 2)
UserForm2.TextBox4 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 3)
UserForm2.TextBox5 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 4)
UserForm2.TextBox6 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 5)
UserForm2.TextBox7 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 6)
UserForm2.TextBox8 = VBA.Format(UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 7), "#,##.00")
UserForm2.TextBox9 = VBA.Format(UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 8), "dd.mm.yyyy")
UserForm2.TextBox10 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 0)
Unload UserForm1
UserForm2.Show
End Sub

screenshot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top