![]() |
cell protection
I am using this script which inserts a time stamp when a user selects an
option from a validated list: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 2 Then Target.Offset(0, 1).Value = Now() End Sub What I need to do is protect the timestamp so a user cannot alter it manually. When protect the cells, the script will not run because the protection blocks it. Is there any way to allow the script to enter the timestamp, but block users from changing the timestamp? Also, is it possible to make the script run only once per cell? I dont want the timestamp to change if the user selects another option in the same cell at a later time if possible. Thanks |
cell protection
Assumptions.............
Column B is currently unlocked. Worksheet is currently protected with password of "justme" Paste this into the sheet module. Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False If Target.Cells.Column = 2 Then ActiveSheet.Unprotect Password:="justme" n = Target.Row If Target.Value < "" _ And Target.Offset(0, 1).Value = "" Then With Target.Offset(0, 1) .Value = Now .Locked = True End With End If End If enditall: Application.EnableEvents = True ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _ Contents:=True, Scenarios:=True End Sub Gord Dibben MS Excel MVP On Fri, 15 Dec 2006 09:42:00 -0800, nkidd wrote: I am using this script which inserts a time stamp when a user selects an option from a validated list: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 2 Then Target.Offset(0, 1).Value = Now() End Sub What I need to do is protect the timestamp so a user cannot alter it manually. When protect the cells, the script will not run because the protection blocks it. Is there any way to allow the script to enter the timestamp, but block users from changing the timestamp? Also, is it possible to make the script run only once per cell? I dont want the timestamp to change if the user selects another option in the same cell at a later time if possible. Thanks |
cell protection
The script is not unprotecting the sheet. If i start with an unprotected
sheet, it does put the time stamp in, and it does protect the sheet. But then if i try to use it again, it does not unprotect the sheet and gives me the normal "the cell or chart you are trying to change is protected..." message. Do you see why it isnt working? "Gord Dibben" wrote: Assumptions............. Column B is currently unlocked. Worksheet is currently protected with password of "justme" Paste this into the sheet module. Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False If Target.Cells.Column = 2 Then ActiveSheet.Unprotect Password:="justme" n = Target.Row If Target.Value < "" _ And Target.Offset(0, 1).Value = "" Then With Target.Offset(0, 1) .Value = Now .Locked = True End With End If End If enditall: Application.EnableEvents = True ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _ Contents:=True, Scenarios:=True End Sub Gord Dibben MS Excel MVP On Fri, 15 Dec 2006 09:42:00 -0800, nkidd wrote: I am using this script which inserts a time stamp when a user selects an option from a validated list: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 2 Then Target.Offset(0, 1).Value = Now() End Sub What I need to do is protect the timestamp so a user cannot alter it manually. When protect the cells, the script will not run because the protection blocks it. Is there any way to allow the script to enter the timestamp, but block users from changing the timestamp? Also, is it possible to make the script run only once per cell? I dont want the timestamp to change if the user selects another option in the same cell at a later time if possible. Thanks |
cell protection
It is not working because you missed a couple of steps at the beginning.
Please note the "Assumptions" Column B is selected then unlocked via FormatCellsProtection and uncheck "Locked" Worksheet is protected with a password of "justme" You start with those parameters. Then you select a cell in column B and enter a value. The sheet is unprotected, a Date is entered in Column C and sheet is re-protected. Gord On Mon, 18 Dec 2006 08:15:00 -0800, nkidd wrote: The script is not unprotecting the sheet. If i start with an unprotected sheet, it does put the time stamp in, and it does protect the sheet. But then if i try to use it again, it does not unprotect the sheet and gives me the normal "the cell or chart you are trying to change is protected..." message. Do you see why it isnt working? "Gord Dibben" wrote: Assumptions............. Column B is currently unlocked. Worksheet is currently protected with password of "justme" Paste this into the sheet module. Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False If Target.Cells.Column = 2 Then ActiveSheet.Unprotect Password:="justme" n = Target.Row If Target.Value < "" _ And Target.Offset(0, 1).Value = "" Then With Target.Offset(0, 1) .Value = Now .Locked = True End With End If End If enditall: Application.EnableEvents = True ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _ Contents:=True, Scenarios:=True End Sub Gord Dibben MS Excel MVP On Fri, 15 Dec 2006 09:42:00 -0800, nkidd wrote: I am using this script which inserts a time stamp when a user selects an option from a validated list: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 2 Then Target.Offset(0, 1).Value = Now() End Sub What I need to do is protect the timestamp so a user cannot alter it manually. When protect the cells, the script will not run because the protection blocks it. Is there any way to allow the script to enter the timestamp, but block users from changing the timestamp? Also, is it possible to make the script run only once per cell? I dont want the timestamp to change if the user selects another option in the same cell at a later time if possible. Thanks |
All times are GMT +1. The time now is 03:28 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com