Forum Discussion

StevenP2205's avatar
StevenP2205
Copper Contributor
Oct 29, 2024

Excel Macros

Hi everyone, I am trying to figure out how to make a macro that will show and hide up multiple tabs in a excel spreadsheet by using a ActiveX Checkbox.   I am able to show a tab by clicking on that designated checkbox.  I need "SHEET 2" checkbox to show "SHEET 3", "SHEET 4", and "SHEET 5" once checked, then hide those sheets once it is unchecked.  I tried to add a sheet but it wont accept macro enabled sheets.

  • StevenP2205's avatar
    StevenP2205
    Copper Contributor

    So I have figured out how to unhide them when the checkbox is checked but cant figure out how the rest of the code to hide them again once its unchecked.  Here is what i have so far:

     

    Private Sub CheckBox1_Click()


    Dim sh As Excel.Worksheet

    For Each sh In Sheets(Array("Sheet2", "Sheet3", "Sheet4"))
    sh.Visible = Not CheckBox2.Value
    Next


    End Sub

Resources