PDA

View Full Version : Uncheck Chckbox in Protected Sheet



usman5594
07-25-2013, 12:21 AM
Hi
i Need Help About Clear All Checkbox on my Sheet " Sheet2"
i use this code



Sub Clear_Check()
ActiveSheet.CheckBoxes.Value = False
End Sub
its work grate but when i protect the Sheet its give a error "1004"


And Can This Macro Run Automatically When Sheet2 is Activate

Kindly help

http://www.excelforum.com/excel-programming-vba-macros/941985-uncheck-chckbox-in-protected-sheet.html

SamT
07-25-2013, 05:37 AM
This code must go in the Worksheet's code page

Private Sub Worksheet_Activate()
ActiveSheet.Protect contents:=False
ActiveSheet .CheckBoxes.Value = False
'Do other code here
ActiveSheet .Protect contents:=True, userinterfaceonly:=True

End Sub

Or use this code, which must be in the ThisWorkbook Code page

Private Sub Workbook_SheetActivate(ByVal Sht As Object)
'If statement prevents code from running on wrong sheets.
If Sht.Name = "Name of desired Sheet" Then 'Modify to suit
With Sht
.Protect contents:=False
.CheckBoxes.Value = False
'Do other code here
.Protect contents:=True, userinterfaceonly:=True
End With
End If

End Sub

mikerickson
07-27-2013, 06:58 PM
Alternatly, you could uncheck the Locked box when creating the Check Box