VBA in protected sheet unprotects the sheet

Status
Not open for further replies.

kkyuvaraj

New Member
Joined
Apr 25, 2019
Messages
37
Hi,

I have below code in a protected worksheet and the sheet automatically become unprotected if i enter value in any cell.

Someone help me to alter the code, if i select "Yes" in Cell No:F50, then the Rows("51:59") need to unhide and allows users to enter data but the sheet should not unprotect.Or else the rows remain Hidden.

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
        [ /Code]

End If
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
are you protecting the sheet only to hide and unhide rows?
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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