How to Show or Hide Excel Text Boxes Based on User Input Using VBA
Question details
The user needs to control the visibility of specific text boxes on an Excel dashboard depending on user selections.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating an interactive Excel dashboard where users can choose which text boxes, linked to table data, are displayed at any given time.
- Observed behavior
- By default, the text boxes remain statically visible. The goal is to make them dynamically appear or disappear based on inputs like ActiveX check boxes.
Ensure that the Developer tab is enabled in your Excel ribbon and that you save your workbook as a Macro-Enabled Workbook (.xlsm) to allow VBA code to function properly.
Use VBA and ActiveX Check Boxes to Toggle Text Box Visibility
This method uses a simple VBA script triggered by an ActiveX check box to evaluate the user's input and dynamically change the visibility property of a specific text box.
By utilizing ActiveX controls rather than standard Form controls, you can embed event-driven VBA code directly into the control itself. This makes it much easier to detect when a user clicks the check box and instantly update the dashboard layout.
Navigate to the Developer tab, click 'Insert', and choose the 'Check Box' from the ActiveX Controls section. Click and drag on your dashboard to draw the check box.
Click on the text box you want to hide or show. Look at the Name Box located to the left of the formula bar to note its exact name (for example, 'TextBox 1').
Right-click the newly inserted ActiveX Check Box and select 'View Code'. This will automatically open the VBA editor and create a 'Click' event sub-routine for the check box.
In the code window, enter the following logic: If CheckBox1.Value = True Then ActiveSheet.Shapes("TextBox 1").Visible = msoTrue Else ActiveSheet.Shapes("TextBox 1").Visible = msoFalse End If. Replace 'TextBox 1' with the name you identified earlier.
Close the VBA editor and make sure you exit 'Design Mode' by clicking the Design Mode button in the Developer tab. Click the check box to verify the text box dynamically shows and hides.

Create Interactive Spreadsheets with WPS Office
WPS Spreadsheet offers powerful developer tools and full VBA support, making it simple to create interactive dashboards, utilize ActiveX controls, and run dynamic macros just like in Microsoft Excel.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your .xlsm dashboard file or create a new one.
- 2. Access Developer Tools: Navigate to the Developer tab on the ribbon. If it is hidden, enable it in the WPS Options menu under customize ribbon.
- 3. Manage Controls and Macros: Use the 'Insert' button to add ActiveX check boxes, and click 'Visual Basic' to paste or edit your VBA code for hiding dashboard text boxes.

Frequently Asked Questions
Why isn't my VBA code hiding the text box?
Ensure you have spelled the text box name exactly as it appears in the Name Box (including spaces). Also, make sure you have exited 'Design Mode' in the Developer tab, as macros will not trigger while you are still editing the layout.
Can I use standard Form Controls instead of ActiveX Controls?
Yes, but standard Form Controls require you to assign a macro to them manually. You would need to write a standalone macro in a standard module and right-click the Form Control check box to assign that macro, instead of using a direct click event.
Do I have to save the file in a specific format?
Yes, to retain your VBA macros and interactive dashboard features, you must save your file as an Excel Macro-Enabled Workbook (.xlsm) or an Excel Binary Workbook (.xlsb).
How do I hide multiple text boxes with one check box?
You can expand the VBA code to target multiple shapes within the same IF statement. Just add additional lines like `ActiveSheet.Shapes("TextBox 2").Visible = msoFalse` under the respective True and False conditions.




