toggle protection whilst running code.
Sub UnHideRow()
ActiveSheet.Unprotect
Worksheets("Grading Sheet").Rows.Hidden = False
Sheets("Grading Sheet").Shapes("Button 1").Visible = True
Sheets("Grading Sheet").Shapes("Button 2").Visible = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub HideRow()
Dim lLastRow As Long
Dim lCounter As Long
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Sheets("Grading Sheet").Shapes("Button 1").Visible = False
With Worksheets("Grading Sheet") 'Change to suit
lLastRow = .Range("BD65536").End(xlUp).Row
For lCounter = 14 To lLastRow
If .Cells(lCounter, "BD").Value = 1 Then
.Cells(lCounter, "BD").EntireRow.Hidden = True
'Else: .Cells(lCounter, "BD").EntireRow.Hidden = False
End If
Next lCounter
.Range("A14").Select
End With
Sheets("Grading Sheet").Shapes("Button 2").Visible = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
You also need to format the cells so that the locked property is only set for cells in J,OPQ.
Because you have merged cells you will need to select the cell range J14:134
I have not used a password on sheet protection
Bookmarks