Show Hide User Form Controls Using Check Box

A question asked by one of website visitors Marshall:

Dear Dinesh,
Thank you for all your help, my userform has developed since we last spoke, I have updated it using your example and this is working well.
I understanding have attached this for you to see.

My burning question now is, can a combobox be hidden and only appear after an input from another text or combo box.

Example, on my form the first input box is a textbox demanding that you choose an option even if the option is zero.
What I would like is for all the combo boxes below be hidden until I have made the selection in the first textbox.

Then the user continues to fill in the boxes, can this be done?


Another Microsoft Excel VBA question?
I’m creating UserForms in Microsoft Excel, and I want the forms to come up with the textboxes hidden until a check box is selected, what code do I use for this?
Watch the video (about 14 MB) below to see how the controls are inserted, coded and executed to provide an elegant solution.

Here’s the code for the checkbox:
Private Sub CheckBox1_Click()
For Each objCtrl In Me.Controls
‘When you create the first TextBox the default Name is ‘TextBox1’; the second TextBox’s name is TextBox2 & so on
‘Therefore we check for ‘Text’ below using the ‘Left’ text function
‘If you change the Name of your controls then you must code accordingly
If Left(objCtrl.Name, 4) = “Text” Then objCtrl.Visible = CheckBox1.Value
End Sub

This is the VBA code when you start or run the user-form:
Private Sub UserForm_Initialize()
CheckBox1.Value = False
For Each objCtrl In Me.Controls
If Left(objCtrl.Name, 4) = “Text” Then objCtrl.Visible = False
End Sub

You can similarly use any control like a ‘text box’ or a ‘combo-box’ to show or hide other controls on your user-form by carefully coding the relevant control.

Notice how the ‘for each loop’ is used with good effect. For more ‘for loop’ solutions you can search the macros area of the website.
If you wish to know more about how to create user-forms, insert controls and add coding to the controls, you can watch the videos here under VBA user forms.

2 thoughts on “Show Hide User Form Controls Using Check Box

  1. Harsh

    Hi Sir,

    Please help me with the issue i have mentioned below related to the check box.

    Supposedly i have 2 Different Check Box, and i wish to link each check box with 3 different fields, i.e. one List Box, and two text box under One Check Box. Now as mentioned above that at the initialization of the user form i want the List box & the text box (for both check box) to be hidden. Now when i select the 1st check Box, it should show(Activate) the List Box & The Text box of that particular check box i wish to link and similarly when i select the 2nd check box.

    I have also customized the names of my text box & the list box as per my convenience.

    Please also help me by explaining the following code.

    If Left(ObjCtrl.Name, 4) = “text” Then ObjCtrl.Visible = CheckBox1.Value

    What is 4 in the code. is it the no. of alphabet?? Then do i need to create separate code for separate text box name?? Please help me with the same.

    Thanks & Regards


    1. Dinesh Kumar Takyar Post author

      Of course you can code the check boxes so that only a specific list-box and text-boxes are displayed using the strategy described.
      Every text-box if not renamed by you has the name TextBox1, TextBox2, and so on. The 4 refers to the number of characters that have to be checked for from the left of ‘TextBox’ which gives us ‘text’.


Leave a Reply

Your email address will not be published. Required fields are marked *