Worksheet Hide / Unhide

mrowe

Board Regular
Joined
Feb 17, 2002
Messages
232
Hi,

Being Friday, by brain has ground to a halt (again).

What I want to do is hide sheet3 if it is visable or do nothing if it is hidden on each workbook close.

I thought of using a flag like if visable then 1 else 0
If 1 then show else hide etc..

Any ideas?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Visible = False

End Sub

Thanks
Matt
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

BBHRVS

Board Regular
Joined
Nov 3, 2005
Messages
94
At the end, anyway, you want to hide it ??
So no condition required (if I am not too tired also...)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Thisworkbook.Sheets("Sheet3").visible=false
End Sub
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I don;t think you need to test its visibility. Your code will already hide it if it's visible and do nothing if it isn't.

If you want to toggle the visibility:

Code:
With Sheets("Sheet3")
   .Visible = Not .Visible
End With
 

mrowe

Board Regular
Joined
Feb 17, 2002
Messages
232
this is ok but it's not visable all the time so I need some error trapping to look at it to see if it's visable or not first
 

BBHRVS

Board Regular
Joined
Nov 3, 2005
Messages
94
Then you have :

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set mysh=Thisworkbook.Sheets("Sheet3")
If mysh.visible =true then
mysh.visible=false
'any other action
Else
'any action
End if
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,540
Messages
5,572,794
Members
412,483
Latest member
deezina07
Top