Consulting

Results 1 to 3 of 3

Thread: Uncheck Chckbox in Protected Sheet

  1. #1

    Uncheck Chckbox in Protected Sheet

    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-prog...ted-sheet.html

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Alternatly, you could uncheck the Locked box when creating the Check Box

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •