when i am running this macro to protect and unprotect in given range it is protecting as well and when i am again running this macro to unprotect it's not unprotecting
Code
Sub lockcells()
Dim Rng
Dim MyCell
Set Rng = Range("A1:D20")
For Each MyCell In Rng
If MyCell.Value = "" Then
Else: ActiveSheet.UnProtect Password:="123"
MyCell.Locked = True
MyCell.FormulaHidden = False
ActiveSheet.Protect Password:="123", UserInterFaceOnly:=True
End If
Next
End Sub
Display More