Hiding / Unhiding Sheets

L

Larry Fitch

I have created macros to hide and unhide sheets when clicking on a button

example -
Sheets("Premium Labor Utilization").Visible = Not Sheets("Premium Labor
Utilization").Visible

I am also assigning goups of sheets to a summary button

example
Application.ScreenUpdating = False
Sheets("Premium Labor Utilization").Visible = Not Sheets("Premium Labor
Utilization").Visible
Sheets("FMLA Compliance").Visible = Not Sheets("FMLA Compliance").Visible
Sheets("FLSA Compliance").Visible = Not Sheets("FLSA Compliance").Visible
Sheets("Compliance Rpt").Visible = Not Sheets("Compliance Rpt").Visible
Sheets("Tangible Savings Summary").Visible = Not Sheets("Tangible
Savings Summary").Visible
Sheets("Selection Sheet").Select

The problem is that if I have already opened a sheet with an idividual
button - it will close if I click on a summary button and it is one of the
sheets that are part of the summary macro.

Is there any way to add some sort of error checking around this so that if a
sheet is already open it will not be closed ?
 
J

JLatham

Since I presume your summary button(s) will know what sheets are involved in
the summary, you could be more pro-active in determining what sheets to
display and which to hide, as
Sheets("InSummary1").Visible=True
Sheets("InSummary2").Visible=True
Sheets("InSummary3").Visible=True
Sheets("NotInSummary1").Visible = False
Sheets("NotInSummary2").Visible = False

or you can actually test each, as with:
If Not Sheets("InSummary1").Visible Then
Sheets("InSummary1").Visible=True
End If
and
If Sheets("NotInSummary2").Visible Then
Sheets("NotInSummary2").Visible = False
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top