title: Hide/Unhide sheets - VBA
body: <p>I have a worksheet containing 15 different sheets. I want a "main menu" sheet from where I can just click a button and then be redirected to the chosen sheet, while keeping all the other sheets hidden. From the chosen sheet I want to be able to go back to the "main menu" sheet again and still keep everything hidden. Thus, only one sheet will show at the time.</p>
  
  <p>My problem is the following;
  The VBA code that I use is working perfectly, but sometimes it shows the error 
  <a href="https://i.stack.imgur.com/g6BCZ.png" rel="nofollow noreferrer">Run time error '1004': Method 'Visible' of object '_Worksheet'failed</a>
  , and when I go to debug it shows the following <a href="https://i.stack.imgur.com/gvt3j.png" rel="nofollow noreferrer">debug screen</a>.</p>
  
  <p>As mentioned the code works "perfectly", but sometimes the run time error 1004 pops up. What am I doing wrong? The code is the following;</p>
  
  <pre><code>Sub Button8_Click()
  Sheet3.Visible = xlSheetVisible
  Dim sh As Worksheet
  
      For Each sh In ThisWorkbook.Sheets
          If sh.Name &lt;&gt; "practice group - mtd" Then
              sh.Visible = xlSheetHidden
          End If
      Next sh
  End Sub
  </code></pre>