How to Show or Hide Multiple Excel Worksheets with an ActiveX Check Box
Question details
The user needs to control the visibility of multiple worksheets simultaneously using an ActiveX check box and a VBA macro.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Creating an interactive workbook where users can toggle the display of specific sheets (e.g., Sheet3, Sheet4, Sheet5) with a single click.
- Observed behavior
- Multiple worksheets need to dynamically switch between visible and hidden states based on the boolean value of an ActiveX check box on a main sheet.
Ensure that the Developer tab is enabled in your Office ribbon and that your macro security settings allow VBA code execution.
Use an ActiveX Check Box Click Event
Add VBA code to the Click event of an ActiveX check box to loop through target worksheets and toggle their visibility automatically.
This method uses an ActiveX control rather than a Form control because ActiveX controls have built-in event handlers directly inside the worksheet module. When the check box is clicked, the macro instantly triggers.
The VBA script utilizes the 'IIf' function to evaluate the check box's value (True or False) and then assigns 'xlSheetVisible' or 'xlSheetHidden' to each sheet's 'Visible' property.
Go to the Developer tab, click 'Insert', and select 'Check Box (ActiveX Control)'. Draw the check box on your main worksheet (e.g., Sheet2).
Right-click the newly inserted check box and select 'View Code'. This automatically opens the Visual Basic for Applications (VBA) editor linked to that sheet's module.
Enter the following code to loop through your desired sheets: Private Sub CheckBox1_Click() Dim sh As Worksheet For Each sh In Worksheets(Array("Sheet3", "Sheet4", "Sheet5")) sh.Visible = IIf(Me.CheckBox1.Value, xlSheetVisible, xlSheetHidden) Next sh End Sub
Close the VBA editor window. On the Developer tab, click 'Design Mode' to turn it off. Click your check box on the sheet to test hiding and showing the specified tabs.
Go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' to ensure your VBA macro is saved correctly.

Build Interactive Workbooks with WPS Spreadsheet
WPS Spreadsheet provides comprehensive support for VBA macros and ActiveX controls, enabling you to build interactive dashboards and automate everyday repetitive tasks effortlessly.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your existing workbook or create a new blank Spreadsheet.
- 2. Enable Developer Tools: Go to Menu > Options > Customize Ribbon, and check the 'Developer' box to access macro and ActiveX features.
- 3. Configure ActiveX Controls: Use the Developer tab to insert your check box, click 'View Code', and paste your VBA script into the built-in code editor.

Frequently Asked Questions
Why is my ActiveX check box not responding to clicks?
Make sure you have turned off 'Design Mode' in the Developer tab. ActiveX controls cannot trigger macros while Design Mode is active. Additionally, check your Trust Center settings to verify that macros are enabled.
Can I use a Form Control check box instead of an ActiveX one?
Yes, but the setup is different. A Form Control check box requires you to write a standard macro in a standalone Module block and then right-click the check box to 'Assign Macro'. It does not utilize private worksheet click events.
How do I ensure users cannot unhide the worksheets manually?
In your VBA script, replace 'xlSheetHidden' with 'xlSheetVeryHidden'. This prevents users from right-clicking a sheet tab and choosing 'Unhide'. The sheets can then only be unhidden via code.
Does WPS Office support macros and ActiveX controls?
Yes, versions of WPS Office that include VBA support can execute macro-enabled workflows smoothly, including ActiveX check box interaction and worksheet visibility toggling.




