#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sumproduct issues SteveDB1 Excel Worksheet Functions 25 June 3rd 09 04:58 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
up to 7 functions? ALex Excel Worksheet Functions 10 April 12th 05 06:42 PM
cell protection D Excel Discussion (Misc queries) 2 March 29th 05 10:58 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"