Unprotect active sheet

BravoBravoAu

Board Regular
Joined
Nov 8, 2011
Messages
64
Office Version
  1. 2016
Platform
  1. Windows
Based on some earlier advice from @Yongle, I've been using a worksheet to track progress on tasks, using the code below to record date, time and by who certain entries are made:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = 1 Then Exit Sub   'ignore changes in header row
   
    If Target.Column = Range("K1").Column Then
        Cells(Target.Row, "L") = Date
        Cells(Target.Row, "M") = Time
        Cells(Target.Row, "N") = Application.UserName
    End If
   
 If Target.Column = Range("R1").Column Then
        Cells(Target.Row, "S") = Date
        Cells(Target.Row, "T") = Time
        Cells(Target.Row, "U") = Application.UserName
    End If
    
If Target.Column = Range("V1").Column Then
        Cells(Target.Row, "W") = Date
        Cells(Target.Row, "X") = Time
        Cells(Target.Row, "Y") = Application.UserName
    End If
    
End Sub

I'm now looking to protect the worksheet as it will be shared and some fields don't need most users to have access to them.

To do so, I expected I would have to modify each of the three above ranges to:

Code:
If Target.Column = Range("K1").Column Then
        ActiveSheet.Unprotect "PASSWORDHERE"
        Cells(Target.Row, "L") = Date
        Cells(Target.Row, "M") = Time
        Cells(Target.Row, "N") = Application.UserName
        ActiveSheet.Protect "PASSWORDHERE", True, True
    End If

But I'm continuing to get "run-time error 1004". When I debug, the first line (date) is highlighted.

HELP?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here is how you can do what you want.

You can modify this and add in the Password and UserName

You should be able to see the logic

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  10/4/2018  1:16:02 AM  EDT
If Target.Column = 11 Then
    Target.Offset(, 1).Value = Date
    Target.Offset(, 2).Value = Time
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top