Cells unlocking for no (apparent) reason

Status
Not open for further replies.

MiguelG

New Member
Joined
Sep 16, 2018
Messages
4
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:

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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top