Hi to all,
I'm developing a workbook containing 121 sheets. Sheet 1 is effectively an index, and uses 120 form control checkboxes to unhide and display the selected sheets individually.
The code I'm using for each checkbox is below and is in a module.
Sub CheckBox1_Click()
Dim s As String, cbx As CheckBox
s = Application.Caller
Set cbx = ActiveSheet.CheckBoxes(s)
If cbx.Value = xlOn Then
Sheet2.Visible = xlSheetVisible
Sheet2.Select
Else
Sheet2.Visible = xlSheetHidden
End If
End Sub
The code will hide the sheet again if the box is unchecked, and this is what should be done by the operator before closing the workbook. Surprise - that doesn't always happen.
I've worked out that adding the following code (for each sheet) to the workbook module does the job of hiding the sheets on opening.
Private Sub Workbook_Open()
Sheet2.Visible = xlSheetHidden
End Sub
I'm left with two problems and any help will be greatly appreciated.
Code to hide all the sheets on opening the workbook (except sheet 1), rather than repeating the line above 120 times?
Code to uncheck (on opening the workbook) any checkboxes which had not been unchecked when the worbook was last saved/closed? My preference is to do this automatically rather than with a macro requiring some user input.
I'm very new to vba (still at the guess-copy-try stage) so apologies if the questions have simple or obvious answers.
Thanks in advance.
Cheers.
Bookmarks