Forum Discussion

Doc441's avatar
Doc441
Copper Contributor
Apr 03, 2020

Can you create a checkbox that will hide or show a tab in a worksheet?

If I create a yes/no button could it trigger the hiding or exposing of an additional tab in the same worksheet?

7 Replies

  • Lewis-H's avatar
    Lewis-H
    Iron Contributor
    Use checkbox to hide or unhide worksheet in Excel.
    Open the worksheet contains the Checkbox1, right click the sheet tab, and then click View Code from the right-clicking menu.
    Note: The check box should be ActiveX check box when you inserting.
  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    Doc441 You need a small piece of VBA code for that. Create your checkbox, right-click it and select "Format Control..." and select the Cell Link (for example A1) and OK. Right-click again and "Assign Macro...". Now you select the macro that does the hiding and unhiding. Example below:

    Sub Macro1()
    Dim HideSheet As Boolean
    HideSheet = Range("A1")
    
    If HideSheet Then
        Sheets("Sheet1").Visible = False   
        Else
        Sheets("Sheet1").Visible = True
        End If
        
    End Sub

     This code assumes you have a check box linked to A1. It will hide "Sheet1" when ticked, and unhide it when not ticked. The attached workbook contains a working example.

    • Doc441's avatar
      Doc441
      Copper Contributor

      Riny_van_Eekelen Thanks for the reply....I would call myself an intermediate user but the coding seems to be an issue.

      I am unsure of the HideSheet = Range("A1") component....

      Thats the line that seems to be erroring.

       

      I appreciate your guidance 

Resources