Timestamp on a protected sheet

Anonymous
2015-04-07T04:47:34+00:00

Hello,

I have a spreadsheet that is automatically protected after data entry. Kind folks here helped me put in a procedure for protecting and unprotecting data sheet after data entry.

Now, I would like to populate cells E1:E14 if the adjacent cell A1:A14 is populated. But since the worksheet protects itself after data-entry, this is proving to be a bit of a trouble. Can someone please help?

Many Thanks in advance

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    LockUsed

    Me.Save

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    LockUsed

End Sub

Sub LockUsed()

    Dim trg As Range

    Dim rng As Range

    With Worksheets("Sheet1")

        .Unprotect Password:="secret"

        Set trg = Worksheets("Sheet1").Range("A1:C14")

        On Error Resume Next

        Set rng = trg.SpecialCells(xlCellTypeConstants)

        If Not rng Is Nothing Then

            rng.Locked = True

        End If

        Set rng = Nothing

        Set rng = trg.SpecialCells(xlCellTypeFormulas)

        If Not rng Is Nothing Then

            rng.Locked = True

        End If

        .Protect Password:="secret"

    End With

End Sub

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

        With Target

            If .Count > 1 Then Exit Sub

            If Not Intersect(Range("A1:A14"), .Cells) Is Nothing Then

                Application.EnableEvents = False

                If IsEmpty(.Value) Then

                    .Unprotect Password:="secret"

                    .Offset(0, 4).ClearContents

                Else

                    With .Offset(0, 4)

                        .Unprotect Password:="secret"

                        .NumberFormat = "dd mmm yyyy hh:mm:ss"

                        .Value = Now

                    End With

                End If

                Application.EnableEvents = True

            End If

        End With

    End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2015-04-07T08:37:26+00:00

    You are amazing Hans!!!

    Thank you for the prompt reply and for all your help.

    Kind Regards

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more