Search code examples
excellistboxuserformvba

ListBox selection that can be clicked to open another UserForm


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.


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