Hi everyone,
The code below works perfectly as long as the sheet is unlocked when the watched cell changes. By working perfectly, I mean that when the data in the current row column C changes from blank to any data entered, the current static date and time is entered into a cell 26 columns away from cell C in column AC. The problem is that I have been completely unsuccessful using sheet locking and unlocking code in this worksheet change event like I use it within macros. I need for it to unlock the sheet with a password I specify, apply the change and then lock the sheet again and setting the same specified password.
Option Explicit
' *********************************************************
' Create a date/time stamp
' ********************************************************
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorEvent
' *********************************************************
' Only Allow A Single Cell Range
' *********************************************************
If Target.Cells.Count > 1 Then
Exit Sub
End If
' ********************************************************
' Turn Off EnableEvents To Prevent Looping
' ********************************************************
Application.EnableEvents = False
' ********************************************************
' Apply the Change If Data is Entered in Current Row Column C
' ********************************************************
If Not Application.Intersect(Target, Columns("C")) Is Nothing Then
Cells(Target.Row, Target.Column + 26) = Now()
End If
ExitNormally:
' ********************************************************
' Return EnableEvents to Normal Mode
' ********************************************************
Application.EnableEvents = True
Exit Sub
ErrorEvent:
MsgBox Err.Description
Resume ExitNormally
End Sub
I've been trying to use the following to unlock and lock but it doesn't work in the change event.
' Unlock the sheet
Set wsh = Worksheets("Youth")
On Error Resume Next
wsh.Unprotect Password:="Rcdc"
'
' Lock the sheet
wsh.Protect Password:="Rcdc"
I need some words of VBA guru wisdom.
Can you help?
Bookmarks