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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,812
Messages
5,833,803
Members
430,233
Latest member
cbutts

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top