Jmoz092
Board Regular
- Joined
- Sep 8, 2017
- Messages
- 184
- Office Version
- 365
- 2011
- Platform
- Windows
- MacOS
I'm having trouble locking a range of cells if a VBA password prompt does not enter specific user names into a cell. I want any users to be able to edit range A1:I11, but I only want 2 specific users to be able to edit anything else on the sheet (codename sheet1).
The user's name is determined at a password prompt and then entered in to cell K18. If the value of K18 does not equal "user1" or "user2", then I want to lock range A12:R61.
I can't get the code to keep the cells locked, and I think I'm also missing the worksheet_change function. Is there something similar for range_change??
I have this code inserted into Sheet1:
The user's name is determined at a password prompt and then entered in to cell K18. If the value of K18 does not equal "user1" or "user2", then I want to lock range A12:R61.
I can't get the code to keep the cells locked, and I think I'm also missing the worksheet_change function. Is there something similar for range_change??
I have this code inserted into Sheet1:
Code:
Sub worksheet_change(ByVal target As Range)
Dim pwR As Range
Set pwR = Range("K18")
If pwR <> "user1" Or pwR.Value <> "user2" Then
range("a1:I11").Locked = False
Range("a12:r61").Locked = True
MsgBox "You do not have authorization to edit these cells." & vbCr & "Only Zuul, user1, or user2 may edit these cells." & vbCr & "The range is now locked."
End If
End Sub
Last edited: