ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lock Range of Cells (https://www.excelbanter.com/excel-programming/427735-lock-range-cells.html)

Pam[_3_]

Lock Range of Cells
 
Hi,

I have the following code that isn't working to lock the range of cells
listed on ss selected. By applying activesheet.protect, do I still need to
go to formatcells or toolsprotection and set a password to protect this
sheet or does this line of code provide for that?

Sub DTProtectWhiteSpaceAllProd()
Worksheets("DT").Select
Cells.Select
Selection.Locked = False
Range("A146:A160").Select
Selection.Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
End Sub

If anyone can tell me what I'm doing wrong I would appreciate it.
Thanks,
Pam



AltaEgo

Lock Range of Cells
 
You code tests OK for me. One minor suggestion is to unlock the sheet before
running your code.


Sub DTProtectNoPassword()
Worksheets("DT").Select
ActiveSheet.Unprotect 'enure it is unlocked
Cells.Select
Selection.Locked = False
Range("A1:A16").Select
Selection.Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
End Sub

Sub ProtWithPW()

Worksheets("DT").Select
ActiveSheet.Unprotect Password:="yourPassword"
Cells.Select
Selection.Locked = False
Range("A1:A16").Select
Selection.Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:="yourPassword"

End Sub


--
Steve

"Pam" wrote in message
...
Hi,

I have the following code that isn't working to lock the range of cells
listed on ss selected. By applying activesheet.protect, do I still need
to go to formatcells or toolsprotection and set a password to protect
this sheet or does this line of code provide for that?

Sub DTProtectWhiteSpaceAllProd()
Worksheets("DT").Select
Cells.Select
Selection.Locked = False
Range("A146:A160").Select
Selection.Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
End Sub

If anyone can tell me what I'm doing wrong I would appreciate it.
Thanks,
Pam



All times are GMT +1. The time now is 02:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com