Hi
I have some code that hides rows in a spreadsheet but it doesn't work when I protect the worksheet. Can anybody tell me the code to unprotect the sheet before it runs the hide rows bit and then protect the sheet at the end of the code. Sorry I know this is probably really simple but I've only just started to write macros again after a loooooooooong break.
Many thanks.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("REF_TYPE")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
With Sheets("Referral Form")
If Range("REF_TYPE_LKP").Value = 0 Then Rows("6:70").EntireRow.Hidden = True
If Range("REF_TYPE_LKP").Value = 1 Then Rows("6:70").EntireRow.Hidden = False
If Range("REF_TYPE_LKP").Value = 1 Then Rows("29:35").EntireRow.Hidden = True
If Range("REF_TYPE_LKP").Value = 2 Then Rows("6:70").EntireRow.Hidden = False
If Range("REF_TYPE_LKP").Value = 2 Then Rows("29:35").EntireRow.Hidden = False
End With
End If
End Sub
Bookmarks