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