My VBA Code will not work when the sheet is protected?

Anonymous
2018-08-14T11:09:05+00:00

I'm using the following VBA code...

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B:H")) Is Nothing Then

If Target.Count > 1 Then Exit Sub

Cells(Target.Row, "M").Value = Environ("username") & ", " & Format(Now, "yyyy/mm/dd  hh:mm:ss")

End If

End Sub

It works fine if I leave the sheet unprotected. But when I protect the sheet in order to lock specific cells, I get a Debugger message box.

Do I need to alter the VBA code to allow it to work when the sheet is protected?

Many thanks.

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

3 answers

Sort by: Oldest
  1. 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

  2. Anonymous
    2018-08-14T14:24:01+00:00

    That's done the trick perfect!

    You have my sincere thanks HansV!

    Was this answer helpful?

    0 comments No comments
  3. 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