I have applied this macro to protect and unprotect in given range of cells in a sheet here is a problem i am facing in this macro When I run this macro this macro is protecting in given range of cells A1 to D20 and when I am run again this macro to unprotect in given range it's not unprotecting
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
I want to protect and unprotect with single macro