I need a userbox (ListBox or CheckBox) to Hide / Unhide selected sheets. I have ~6 sheets (Summary, Data, Instructions, etc) that will be static, and 10 sheets (000, 100, 200, 300, 400, 500, 600, 700, 800 & 900) that I want to Hide / Unhide.
I need for the list or checkbox to show all 10 sheets for selection (Data A1:A10), with the existing hidden sheets unchecked and the existing unhidden sheets checked. I want a select/unselect all button. Also, in addition to hiding and unhiding the sheets I need to write the resulting sheet names to a list (Data B1:B?). I am using the following which shows ALL sheets in the workbook.
'=========================
==========
==========
==========
==========
====
Private Sub Cancel_Click()
UserForm1.Hide
SplashScreen.Show
End Sub
Private Sub OK_Click()
Dim i As Integer
For i = 1 To Sheets.Count
If Controls("Checkbox" & i).Value = True Then Sheets(i).Visible = True _
Else: Sheets(i).Visible = False
Next i
UserForm1.Hide
SplashScreen.Show
End Sub
Private Sub UserForm_Activate()
Dim i As Integer
Dim chb As Control
On Error Resume Next
For J = 1 To 100
Controls.Remove ("Checkbox" & J)
Next
On Error GoTo 0
For i = 1 To Sheets.Count
Set chb = Controls.Add("Forms.Checkb
ox.1", "Checkbox" & i, True)
chb.Caption = Sheets(i).Name
If Sheets(i).Visible = True Then Controls("Checkbox" & i).Value = 1 _
Else Controls("Checkbox" & i).Value = 0
If i <= 15 Then
chb.Top = 20 * i - 15
Else
If i <= 32 Then
chb.Top = 20 * i - 315
chb.Left = 125
Else
chb.Top = 20 * i - 655
chb.Left = 230
End If
End If
Next
End Sub
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work." & vbLf & vbLf & "Please click the OK or Cancel button."
Cancel = True
End If
End Sub
'=========================
==========
==========
==========
==========
====
Start Free Trial