Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Hide a sheet based on a cell condition

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Hide a sheet based on a cell condition

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Hide a sheet based on a cell condition

Hi

Let the macro unprotect an protect again as required.

You say that both workbook and sheets are protected. It is only required to
unprotect sheet2 in my example.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim AnswerCell As Range
pWord = "JustMe"
Set AnswerCell = Range("A1")
If Target.Address = AnswerCell.Address Then
'ActiveWorkbook.Unprotect Password:=pWord
If AnswerCell = "Yes" Then
With Sheets("Sheet2")
.Unprotect Password:=pWord
.Visible = False
.Protect Password:=pWord
End With
ElseIf AnswerCell = "No" Then
With Sheets("Sheet2")
.Unprotect Password:=pWord
.Visible = True
.Protect Password:=pWord
End With
End If
'ActiveWorkbook.Protect Password:=pWord
End If
End Sub

Hopes this helps

---
Per


"noord453" skrev i meddelelsen
...
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.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Hide a sheet based on a cell condition

Per,

Thank you so much, but I am still getting the same error message.

Gerard

"Per Jessen" wrote:

Hi

Let the macro unprotect an protect again as required.

You say that both workbook and sheets are protected. It is only required to
unprotect sheet2 in my example.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim AnswerCell As Range
pWord = "JustMe"
Set AnswerCell = Range("A1")
If Target.Address = AnswerCell.Address Then
'ActiveWorkbook.Unprotect Password:=pWord
If AnswerCell = "Yes" Then
With Sheets("Sheet2")
.Unprotect Password:=pWord
.Visible = False
.Protect Password:=pWord
End With
ElseIf AnswerCell = "No" Then
With Sheets("Sheet2")
.Unprotect Password:=pWord
.Visible = True
.Protect Password:=pWord
End With
End If
'ActiveWorkbook.Protect Password:=pWord
End If
End Sub

Hopes this helps

---
Per


"noord453" skrev i meddelelsen
...
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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide cell values based on a condition in another cell Cat Excel Worksheet Functions 1 January 4th 07 07:21 AM
Hide Columns Based on Condition Skornia115 Excel Programming 9 July 6th 06 04:49 PM
Hide Columns Based on Condition [email protected] Excel Programming 1 July 5th 06 07:40 PM
Hide rows based on a condition KimberlyH Excel Programming 2 March 29th 06 09:03 PM
Hide a row based on one cell's condition Brian Excel Worksheet Functions 1 March 19th 05 11:57 AM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"