VBA & Macro Problems

How to Show or Hide Excel Text Boxes Based on User Input Using VBA

Steve KSteve K Nov 4, 2026 870 views

Question details

The user needs to control the visibility of specific text boxes on an Excel dashboard depending on user selections.

How to Show or Hide Excel Text Boxes Based on User Input
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert an ActiveX Check Box

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.

2
Identify the Text Box Name

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').

3
Add VBA Code to the Control

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.

4
Enter the Toggle Script

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.

5
Test the Dashboard

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.

Use VBA and ActiveX Check Boxes to Toggle Text Box Visibility
Security Warning: Always review third-party VBA code carefully before running it to protect your system and data from potentially harmful macros.
Interactive Dashboards in WPS

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. 1. Open WPS Spreadsheet: Launch WPS Office and open your .xlsm dashboard file or create a new one.
  2. 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. 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.
Full compatibility with Microsoft Excel (.xlsx and .xlsm) formats.Robust VBA and Macro support for automating dashboard elements.Lightweight software with a familiar, easy-to-use interface.Free to download with comprehensive advanced spreadsheet functions.
microsoft office alternative - wps office

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.