Hello all,
I am working on a program in Excel, and I don't want users accidentally changing the values on some cells. Therefore, I have written the following code on workbook open:
As you can see, on one specific sheet (the one that user inputs data) I want it to be protected, but have some range of cells unlocked.
I have 11 work sheets. They all lock and protect correctly, except one (it happens to be the very first sheet, lets call it Welcome sheet). After testing, I have noticed that the Welcome sheet is indeed locking cells and protecting them, just as in "ShData3Months" sheet. I have tried to manually lock all cells and protecting the sheet, however, when I re-run the code, it just goes back to where it was previously.
I'm at a stump and would appreciate any help in solving this issue.
Thanks in advance,
MG
I am working on a program in Excel, and I don't want users accidentally changing the values on some cells. Therefore, I have written the following 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, on one specific sheet (the one that user inputs data) I want it to be protected, but have some range of cells unlocked.
I have 11 work sheets. They all lock and protect correctly, except one (it happens to be the very first sheet, lets call it Welcome sheet). After testing, I have noticed that the Welcome sheet is indeed locking cells and protecting them, just as in "ShData3Months" sheet. I have tried to manually lock all cells and protecting the sheet, however, when I re-run the code, it just goes back to where it was previously.
I'm at a stump and would appreciate any help in solving this issue.
Thanks in advance,
MG