Show/Hide Controls on a User-Form using a Checkbox

Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010



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 comboboxes 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?

Regards
Marshall

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
Next
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
Next
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 codng to the controls, you can watch the videos here under VBA user forms..
                                                        




More Tips (Solutions):
How do I view and edit Microsoft Excel files on an iPad?
Inventory Soluton
How to rename and color worksheet tabs
Copy Worksheet Quickly
Criteria Range
Animations in Microsoft Excel
Create two charts at once
How to avoid errors while working in Excel
How to benefit from Microsoft Excel Templates
How to use Microsoft Excel 2007 with Word 2007 - create mail merge labels
Landscape Oriented Worksheet Template
How to-make a worksheet fit a printed page
How to make your charts more impressive
Perpetual Calendar from 1900 to 9999
How to create your own custom add-in
How to clear  conditional formattng  in Excel worksheets
How to speed up data entry of decimal numbers
How to change the color of the gridlines of an Excel worksheet or hide them
How to use Autosum in Multiple Worksheet Cells Quickly
How to have your free personal assistant in Mcrosoft Excel who reads out the data to you
How to use the status bar in Microsoft Excel to do a quick data analysis
How to calculate equal monthly payments or instalments using a mathematical equation
Data Forms to Enter and Edit Data
View 2 worksheets in same workbook side by side
Accessing a specific worksheet in large workbooks with multiple worksheets
Referencing a cell in another worksheet
How to perform a what-if analysis using a scrollbar form control
An interesting payroll solution
Future Value Solution in Microsoft Excel
Another Interesting Conditional Formatting Solution
DSUM and Array Formulas for addition solutions
IF Function Question
How to use command buttons on a splash screen in MS-Excel
Copy Paste Data from one Excel Worksheet to Another
How to separate comma separated values (csv) in a worksheet cell in Microsoft Excel into rows or columns
Another Interesting Solver solution in Microsoft Excel
Find duplicates in two different Excel worksheets using a macro
How to count data based on multiple criteria - countifs function
How to convert 6/5/2011 into Sunday, 6/5/2011
User Form to perform calculations
An interesting solution using conditional formatting in Microsoft Excel 2007

Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010

Take a two click survey and help us improve our services