I am working in a workbook that has 10 worksheets in it. I have the main page Sheet10 where I want to put the check boxes to hide/unhide the other worksheets depending upon which checkbox is selected. I have all other worksheets set as "Very Hidden" This sheet should be the only one visible when I enter the workbook. Then once I check one of the Check boxes it unhides the associated worksheets. When it is unchecked it hides those sheets. What is happening everything is showing when I enter the workbook and it hides the worksheets that are not assigned to the check box I am selecting. When I unchecked the boxes everything shows.
I have added code to hide and show the worksheets but it isn't working as expected. It is only Hiding the worksheets it isn't unhiding the hidden sheets as I thought it would. I have all other worksheets listed as "Very Hidden". Also, if I click two buttons at the same time it goes funky and doesn't show the right worksheets
Private Sub CheckBox1_Click()
Dim sh As Excel.Worksheet
Application.ScreenUpdating = False
For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.Visible = Not CheckBox1.Value
Next
Application.ScreenUpdating = True
End Sub
Private Sub CheckBox2_Click()
Dim sh As Excel.Worksheet
Application.ScreenUpdating = False
For Each sh In Sheets(Array("Sheet3"))
sh.Visible = Not CheckBox2.Value
Next
Application.ScreenUpdating = True
End Sub
Private Sub CheckBox3_Click()
Dim sh As Excel.Worksheet
Application.ScreenUpdating = False
For Each sh In Sheets(Array("Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet1", "Sheet2", "Sheet8", "Sheet9"))
sh.Visible = Not CheckBox3.Value
Next
Application.ScreenUpdating = True
End Sub
What I want is a Workbook that has the main page shown when I enter and when I click one of the check boxes it shows or hides the related worksheets. I would like if you select more than one button to add those associated worksheets to visible. When all boxes are unchecked it "Very Hidden" them all.
Aucun commentaire:
Enregistrer un commentaire