I have a script for recording passwords. It has a cell where the user enters a code (cell C3) and the script returns (displays) the password in the adjacent cell (D3). The script also allows a user to click a button to generate a new code for a new password. The new code is displayed in cell C4. To make this script work and keep me from mistakenly changing other fields, I have locked the previous 3 cells (C3, D3 and D4 as well as the password and password code cells (G2:F5000). I then Protect the sheet.
What I would like to do is to lock JUST C3 to allow a user to enter a code. I thought I could do this with the ActiveSheet.Protect command but I can't seem to get it to work. Here is the code, with my attempt commented out:
Private Sub Worksheet_Change(ByVal Target As Range)
' ActiveSheet.Unprotect Password:="password"
' Range("c3:g10000").Locked = True - this range encompasses the 3 specific cells and the password and code storage range
Dim PW As Range
If Target.Address <> "$C$3" Then Exit Sub
Application.EnableEvents = False
Set PW = Sheet1.Columns(6).Find(Target)
If Not PW Is Nothing Then
[D3] = PW.Offset(, 1)
Else
MsgBox "Not Found"
End If
' ActiveSheet.Protect Password:="password"
Range("C3").Select
Application.EnableEvents = True
End Sub
Any help would be appreciated.
Bookmarks