I'm having a problem protecting my sheet with a macro. Below is my understanding of the recommended solution, but it is not working (I'm very green with VBA!). I get run-time error 1004 'Unable to set the Hidden Property of the Range class.' Ultimately, I need to protect the sheet but keep unlocked a macro field that hides columns depending on the selected value. Thanks in advance!
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveWorkbook.Unprotect "my.password"
Dim a As Variant, b As String
If Target.Column = 2 And Target.Row = 5 Then
b = Target.Value2
With Range("d8:ab8")
Application.ScreenUpdating = False
.EntireColumn.Hidden = (b <> "Everyone")
If b <> "Everyone" Then
For Each a In .Cells
If a = b Then a.EntireColumn.Hidden = False
Next
Application.ScreenUpdating = True
End If
Application.ScreenUpdating = True
End With
End If
ActiveWorkbook.Protect "my.password"
End Sub
Bookmarks