Checkbox Macro - Will unhide cells on another sheet, but cannot get to hide when unchecked

gfabbott

New Member
Joined
Feb 11, 2009
Messages
17
I have a macro written that will unhide the rows I want to be displayed on another sheet, but I cannot get it so that they will remain hidden when the checkbox is not clicked.

Any help would be appreciated!

I have it written two ways - can you tell me where I'm going wrong?!

Sub RemotePatrols()
'
' RemotePatrols Macro
' Unlock the section for Remote Patrols on The Services Sheet
'


'
If CheckBox = True Then
Sheets("Services").Select
ActiveSheet.Unprotect Password:="Password"
Range("16:31").EntireRow.Hidden = False
ActiveSheet.Protect Password:="Password"
Sheets("Overall Information").Select
End If
If CheckBox = False Then
Sheets("Services").Select
ActiveSheet.Unprotect Password:="Password"
Range("16:31").EntireRow.Hidden = True
ActiveSheet.Protect Password:="Password"
Sheets("Overall Information").Select
End If
End Sub

ORRRRRR

Sub RemotePatrols_Click()


If CheckBox = True Then
Sheets("Services").Select
ActiveSheet.Unprotect Password:="Password"
[16:31].EntireRow.Hidden = False
ActiveSheet.Protect Password:="Password"
Sheets("Overall Information").Select
Else:
Sheets("Services").Select
ActiveSheet.Unprotect Password:="Password"
[16:31].EntireRow.Hidden = True
ActiveSheet.Protect Password:="Password"
Sheets("Overall Information").Select
End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,

depending on which type of control you have on your worksheet try:


For Active X control

Code:
Private Sub RemotePatrols_Click()
    With Sheets("Services")
        .Unprotect Password:="Password"
        .Rows("16:31").EntireRow.Hidden = CBool(Not Me.RemotePatrols.Value)
        .Protect Password:="Password"
    End With
End Sub


Form Forms control

Code:
Sub RemotePatrols_Click()
    With Worksheets("Services")
        .Unprotect Password:="Password"
        .Rows("16:31").EntireRow.Hidden = CBool(Not ActiveSheet.Shapes("RemotePatrols").ControlFormat.Value = xlOn)
        .Protect Password:="Password"
    End With
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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