title: How do I hide a sheet with a button in Excel?
body: <p>I would like to create a button to hide the sheet. Ideally, it would hide the sheet where the button is located. </p>
  
  <p>To be simple, sheet 1 has a form to fill out. The typical name, address, phone number, etc. Sheet 2 and 3 also have the same fields that is going to be referenced to the 'Data' tab as well. On a sheet named 'Data', I will add fields that will populate simply with the = option like (=Data!...)</p>
  
  <p>However, I do not want the Data page in view once the information is added. We all know the simple right click and hide sheet. But sometimes that's too much for some people that will use this sheet and a pretty button would work better. </p>
  
  <p>I was successful using:
  Module 1</p>
  
  <pre><code>Sub SheetCommand()
  If Worksheets("Sheet1").Range("C2").Value &lt;&gt; vbNullString Then
  Worksheets("Sheet2").Visible = False
  Else
  Worksheets("Sheet2").Visible = True
  End If
  End Sub
  </code></pre>
  
  <p>Sheet1 Code:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address &lt;&gt; "$C$2" Then Exit Sub
  Run "SheetCommand"
  End Sub
  </code></pre>
  
  <p>However, I am not very VB savvy and have hit a dead end. Could someone help show me how to apply this to a button? I don't want it to reference the $C$2 field as noted on the example, but just when someone presses the button, the sheet goes away. I'm not worried about getting it back as someone can be ready to get it the old fashioned way. This would help the data entry process for this manual form so much easier.</p>
  
  <hr>
  
  <p>Edit: basically, I need help creating a vba code where I can hide the page. I'd like to create a button where once clicked, it hides that page. I showed an example of a code where I got it to work but it only works if that cell is populated. How do I make it work on button click? </p>
  
  <hr>
  
  <p>I found this code that does what I need but I would like to tell it a specific Sheet Name instead of having to type it in B6 and B7. </p>
  
  <pre><code>Sub ShowHideWorksheets()
  Dim Cell As Range
  For Each Cell In Range("B6:B7")
  ActiveWorkbook.Worksheets(Cell.Value).Visible = Not
  ActiveWorkbook.Worksheets(Cell.Value).Visible
  Next Cell
  End Sub
  </code></pre>