Protected Excelsheet becomes unprotect if clicked in any cell

kkyuvaraj

New Member
Joined
Apr 25, 2019
Messages
37
Hi,

I have an Excel sheet, which I locked certain cells and protected the sheet.

But the protected sheet automatically becomes unprotected if I enter or clcick in any cell, even if protect the sheet with password, the sheet becomes unprotected without password.

can anyone help on this.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
what is the VBA you have attacthed to that shee, specifically worksheet_change
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect Password:="password"
   If Not Application.Intersect(Range("F50"), Range(Target.Address)) Is Nothing Then
        Select Case Target.Value
        Case Is = "Select": Rows("51:59").EntireRow.Hidden = True
                           
        Case Is = "No":  Rows("51:59").EntireRow.Hidden = True
       
        Case Is = "Yes":  Rows("51:59").EntireRow.Hidden = False
                           
         Me.Protect Password:="password"
        End Select
         

End If
End Sub
 
Upvote 0
so your unprotect is the first item and will be processed first, which is why it unprotects
 
Upvote 0
Can you help to rearrange this code without unprotecting and the code also works well if sheet protected.
 
Upvote 0
not tested
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Application.Intersect(Range("F50"), Range(Target.Address)) Is Nothing Then
        Select Case Target.Value
Me.Unprotect Password:="password"
        Case Is = "Select": Rows("51:59").EntireRow.Hidden = True
                        
        Case Is = "No":  Rows("51:59").EntireRow.Hidden = True
      
        Case Is = "Yes":  Rows("51:59").EntireRow.Hidden = False
                          
        
        End Select
    Me.Protect Password:="password"     
End If
End Sub
 
Upvote 0
In what way doesn't it work?
 
Upvote 0
It gives below Error

---------------------------
Microsoft Visual Basic for Applications
---------------------------
Compile error:

Statements and labels invalid between Select Case and first Case
---------------------------
OK Help
---------------------------
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F50")) Is Nothing Then Exit Sub
    ActiveSheet.Unprotect Password:="password"
    Select Case Target.Value
       Case "Select", "No"
           Rows("51:59").EntireRow.Hidden = True
       Case "Yes"
           Rows("51:59").EntireRow.Hidden = False
    End Select
    ActiveSheet.Protect Password:="password"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,451
Members
449,161
Latest member
NHOJ

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