View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
noord453 noord453 is offline
external usenet poster
 
Posts: 17
Default Hide a sheet based on a cell condition

Per,

Thanks, it works. However since the workbook and its sheets are protected
with a password, and there are others using this excel sheet, without them
knowing this password, it is when run giving the following error
"Run-time error '1004':

Unable to set the Visible property of the Worksheet class"

How to overcome this situation?


"Per Jessen" wrote:

Hi

Look at this code. As it's a event code it has to go into the code sheet for
the desired sheet (the sheet where the condition to hide/unhide the other
sheet is).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim AnswerCell As Range
Set AnswerCell = Range("A1")
If Target.Address = AnswerCell.Address Then
If AnswerCell = "Yes" Then
Sheets("Sheet2").Visible = False
ElseIf AnswerCell = "No" Then
Sheets("Sheet2").Visible = True
End If
End If
End Sub

Hopes this helps

---
Per

"noord453" skrev i meddelelsen
...
Hi I want to hide or unhide a sheet, based on the condition set in a cell
on
a other sheet. The question could be show other sheet yes/no. and based on
the answer the sheet is shown, or hidden. The workbook, and the visible
sheets are protected only some cells are free to edit.