ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locked cells (https://www.excelbanter.com/excel-programming/291010-locked-cells.html)

Amy[_6_]

Locked cells
 
How do I lock/unlock cells in code?


Ron de Bruin

Locked cells
 
Hi Amy

Selection.Locked = True

Selection.Locked = False

Or

Range("A1:c10").Locked = True


Or all cells on the worksheet

Cells.Locked = True


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Amy" wrote in message ...
How do I lock/unlock cells in code?




Amy[_6_]

Locked cells
 
okay this is what I have:
Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("worksheet")
If Not .AutoFilterMode Then
.Range("A2").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
Range("C:C,D:D,L:L").Selec
Selection.Locked = True
End With
End Sub

it doesn't lock the cells.... any ideas?
-----Original Message-----
Hi Amy

Selection.Locked = True

Selection.Locked = False

Or

Range("A1:c10").Locked = True


Or all cells on the worksheet

Cells.Locked = True


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Amy" wrote in message

...
How do I lock/unlock cells in code?



.


Ron de Bruin

Locked cells
 
Change the locked before you protect the sheet

Try this

Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("worksheet")
If Not .AutoFilterMode Then
.Range("A2").AutoFilter
End If
.Range("C:C,D:D,L:L").Locked = True
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Amy" wrote in message ...
okay this is what I have:
Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("worksheet")
If Not .AutoFilterMode Then
.Range("A2").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="password", _
Contents:=True, UserInterfaceOnly:=True
Range("C:C,D:D,L:L").Selec
Selection.Locked = True
End With
End Sub

it doesn't lock the cells.... any ideas?
-----Original Message-----
Hi Amy

Selection.Locked = True

Selection.Locked = False

Or

Range("A1:c10").Locked = True


Or all cells on the worksheet

Cells.Locked = True


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Amy" wrote in message

...
How do I lock/unlock cells in code?



.





All times are GMT +1. The time now is 07:49 AM.

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