Activesheet.Protect/Unprotect????

Giggzz

Well-known Member
Joined
Jul 4, 2002
Messages
990
Here's the code in question:
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect
Range("B4:D4,I4:J4,B5:E5,G5:H5,J5,B6,E6:G6,I6:J6,C7:D7,F7:G7,B9:E9,I9:J9,B10:E10,G10:H10,J10,B11,E11:F11,H11:I11,B12:C12,E12,C14:E14,a56,b56,c56,d56,e56,f56,g56,h56,i56,j56").ClearContents
Range("G14:H14,J14,B15,B17,E17,G17:H17,B19,E19,G19:H19,J19,A23:H23,A24:H24,A25:H25,a26:h26,a27:h27,a28:h28,a29:h29,a30:h30,a31:h31,a32:i32,B34:F34,B35:F35,C47:J47,A48:J48,C49:J49,A50:J50,J53,J54").ClearContents
ActiveSheet.Protect
End Sub

getting a method error when I have the Activesheet.Protect/unprotect in code. I need to have the sheet locked and is there any othere way to have the code excute when the sheet is locked?

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I tried your code as is and it works fine. Do you have a password on your sheet? If so use:

ActiveSheet.UnProtect("Passwword")

code here

ActiveSheet.Protect("Passwword")
 
Upvote 0
I just seen that in my search and that fixed the problem..... Thanks for the help!
 
Upvote 0
here's my code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveSheet.Unprotect "keanu"
Sheet1.Range("A56").Offset(0, Range("A56", Range("V56").End(xlToLeft)).Columns.Count).Value = Format(Now, "dd/mm/yy hh:mm:ss")
ActiveSheet.Protect "keanu"
End Sub

The way the code is now the dates print across t he bottom of the sheet. How can a change the code so they will start at D51 to D56 then start again at F51 to F56? Thanks
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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