Hello everyone! I have been working on an Excel spreadsheet for a master thesis, and this is my first time going around and using VBA.
What I am trying to do is have each specific sheet in my workbook be protected against accidental changes of some cells.
Therefore, I am running this code on workbook open:
As you can see, in one of the sheets (where user inputs data) I let some cells be altered.
I am working with 11 sheets and everything is protected as intended, except for ONE specific sheet (it is the very first sheet of the workbook). After some testing, I have noticed that it is indeed locking cells and protecting the sheet, but instead of locking entire sheet, it locks the ranged I specified for "ShData3Months". I have tried to manually lock entire sheet and then have it protected, but when I re-run the code it just goes back to where it was.
I can't seem to find a reason behind this. Would appreciate some help!
Thanks in advance,
MG
What I am trying to do is have each specific sheet in my workbook be protected against accidental changes of some cells.
Therefore, I am running this code on workbook open:
Code:
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim MyMultipleRnage As Range
For Each ws In Worksheets
If (ws.Name = ShData3Months.Name) Then
Set MyMultipleRange = Union(Range("E1:J1"), Range("M1:R1"), Range("U1:V1"), _
Range("A3:XFD1048576"), Range("Y1:XFD2"))
MyMultipleRange.Locked = False
End If
ws.Protect Password:="leugim", DrawingObjects:=False, _
UserInterFaceOnly:=True, Contents:=True
Next ws
End Sub
As you can see, in one of the sheets (where user inputs data) I let some cells be altered.
I am working with 11 sheets and everything is protected as intended, except for ONE specific sheet (it is the very first sheet of the workbook). After some testing, I have noticed that it is indeed locking cells and protecting the sheet, but instead of locking entire sheet, it locks the ranged I specified for "ShData3Months". I have tried to manually lock entire sheet and then have it protected, but when I re-run the code it just goes back to where it was.
I can't seem to find a reason behind this. Would appreciate some help!
Thanks in advance,
MG