Show/Hide Sheets

dyurkovic

New Member
Joined
Dec 9, 2018
Messages
6
Hi All,
This forum has been so helpful as I am trying to learn about VBA and macros. I do have a question. I have a workbook with a ton of worksheets. The main sheet is "2019". Then each month has 3 different sheets: "January Late Cancel", "January No Show", "January Early Departures", then "February Late Cancel", etc.

On sheet "2019" I currently have a button for each month that will toggle between hiding and unhiding the month's sheets, while keeping "2019" open as well. I also have a button for 2019 which will show/hide all of the sheets in the workbook (with the exception of "2019" of course).

Here is my problem: If, for example, the sheets for January are already visible, when I click on the 2019 button, all sheets are visible. This is good. But, if I click on the 2019 button again, all of the sheets EXCEPT the January ones will hide. This does not happen if all of the sheets are hidden to begin with and I click the 2019 button to unhide and then click again to hide. It will hide all sheets.

Can someone help? If i click on the 2019 button to hide all sheets, I want it to hide all sheets, regardless of if they were visible before. Below is the code I am using for the 2019 button:

Sub ShowHide2019()
Dim Cell As Range
For Each Cell In Range("P30:P65")
ActiveWorkbook.Worksheets(Cell.Value).Visible = Not ActiveWorkbook.Worksheets(Cell.Value).Visible
Next Cell
End Sub


Any help is greatly appreciated!
~Deanna
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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
Back
Top