Code:
Private Sub CommandButton1_Click()
Dim wSheet As Worksheet
For Each wSheet In Worksheets
If wSheet.Name = "Planet" Then
wSheet.Unprotect Password:=Text123
ElseIf wSheet.ProtectContents = True Then
wSheet.UnProtect Password:=Text123
Else
wSheet.Protect Password:=Text123
End If
Next wSheet
Above code helps to Protect/Unprotect worksheet but it does not allow autofilter to run, how can i fix this ?