title: Excel VBA worksheet event to toggle between hide / unhide
body: <p>I am working on a project to minimise the number of sheets that are visible in a an excel workbook at any one given time. I am trying to create a parent sheet (which acts as a toggle button) to show/hide child sheets. For example I have a 6 sheets in a workbook: Inputs, Input 1 and Input 2, Outputs, Output 1 &amp; Output 2. Inputs and Outputs will toggle hide and unhide the others worksheets when activated. I have created 2 worksheet level Sub Functions to try and do this. The first one works great, but the other one only works if the first one has been activated and hidden again. Any advice on a better way to do this would be great. I am not sure why excel doesn't have this function already. I tried with arrays, but that doesn't seem to work. I think you need to unhide each tab individually. </p>
  
  <pre><code>'1. Inputs:
  
  Private Sub Worksheet_Activate()
  
  On Error Resume Next
  Sheets("Input 1").Visible = True = Not Sheets("Input 1").Visible = True
  Sheets("Input 2").Visible = True = Not Sheets("Input 2").Visible = True
  Sheets("Input 1").Activate 'needed to deactivate inputs sheet
  
  End Sub
  
  '2. Outputs
  
  Private Sub Worksheet_Activate()
  
  On Error Resume Next
  Sheets("Output 1").Visible = True = Not Sheets("Output 1").Visible = True
  Sheets("Output 2").Visible = True = Not Sheets("Output 2").Visible = True
  Sheets("Output 1").Activate 'needed to deactivate Outputs sheet
  
  End Sub
  </code></pre>