Hi,
I'm a complete novice at VBA code. I am designing a spreadsheet which will be used by "users" and "administrators". The users will be inputting data and administrators will approve that data (leaving a digital signature in the process). For this reason I've
needed to design a protected spreadsheet where some cells are locked and others are not. However, in order to prevent users from changing their data after administrators approve it, I required some sort of auto-lock once the data has been added. I was looking
up VBA code to achieve this and found the following:
Dim
mRg ``As
Range
Dim
mStr ``As
String
Private
Sub Worksheet_BeforeDoubleClick(``ByVal
Target ``As
Range, Cancel ``As
Boolean``)
If
Not Intersect(Range(``"A1:F8"``), Target) ``Is
Nothing Then
``Set
mRg = Target.Item(1)
``mStr = mRg.Value
End
If
End
Sub
Private
Sub Worksheet_Change(``ByVal
Target ``As
Range)
``Dim
xRg ``As
Range
``On
Error Resume Next
``Set
xRg = Intersect(Range(``"A1:F8"``), Target)
``If
xRg ``Is
Nothing Then Exit Sub
``Target.Worksheet.Unprotect Password:=``"123"
``If
xRg.Value <> mStr ``Then
xRg.Locked = ``True
``Target.Worksheet.Protect Password:=``"123"
End
Sub
Private
Sub Worksheet_SelectionChange(``ByVal
Target ``As
Range)
If
Not Intersect(Range(``"A1:F8"``), Target) ``Is
Nothing Then
``Set
mRg = Target.Item(1)
``mStr = mRg.Value
End
If
End
Sub
I should point out this code DOES work quite well. However, what I'd like to have is a system where admins (who will have the password to unprotect the sheet) can amend any data in these special cells, which standard users cannot. Problem is that each time
data is amended or deleted from that field, the sheet automatically re-protects itself. This means the admin would need to unprotect the sheet for EACH cell they want to change - not ideal if there's a large number of cells that need editing.
Is there a way around this, either by amending the code above or with new code? Essentially what would be needed is a way to prevent the code from re-locking the entire spreadsheet each time one of the targeted cells is edited by an admin.
Thanks in advance for any help with this. If anything is unclear I'd be happy to clarify.
Jack