Load Userform Based On Listbox Name

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
Hi All,

I have listbox1 which lists all the userforms in my Activeworkbook.
I am trying to load a userform based on the value selected in the listbox but can't get it to work, can someone please help with a script to load/ show the userform, the userform would be activated by a commandbutton once I select the userform that I want to show/ load.

thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Private Sub ListBox1_Click()

    Select Case ListBox1.Value
    
        Case "Item1"
            UserForm1.Show
            
        Case "Item2"
            UserForm2.Show
            
        Case "Item3"
            UserForm3.Show
            
        Case "Item4"
            UserForm4.Show
            
    End Select

End Sub

Notes:
  • Item1, Item2, Item3, and Item4 are the actual items listed in the ListBox
  • UserForm1, UserForm2...etc are the actual user form names.
 
Upvote 0
Thanks for the code Alphafrog but I wanted a script that would acivate a userform based on the name in the listbox as the listbox lists all the userforms in the workbook and as I keep updating workbboks I would have to keep adding the select case statement and I have several workbooks that have various different forms, that's why I wanted to activate whatever name is in the listbox, similar to activating a workbook through a textbox. example

Code:
workbooks(textbox1.value).activate

I thought that there would be a similar one for userforms even if I have to add the selected name into a textbox and then the textbox activates the form.

I tried codes as following but they don't exist and I can't find anything on google.

Code:
forms(textbox1.value).activate
 
I tried also
 
load textbox1.value
 
I tried also
 
textbox1.value.show
 
Upvote 0
Hello

This is cut down example, of a form that works as you ask.

Code:
Private Sub CommandButton1_Click()
    Select Case ListBox1.ListIndex
        Case 0
            frmTOC.Hide
            frmCheckBoxExample.Show
        Case 1
            frmTOC.Hide
            frmComboBoxExample1.Show
        Case 2
            frmTOC.Hide
            frmComboBoxExample2.Show
   
       
    End Select
End Sub
 
Upvote 0
Thanks for your help everyone,

I have used Alphafrog's example as it is exactly what I was after, much appreciated Alphafrog.:):):)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top