I have the following code below to protect formulas on all sheets
However when running the macro, I get a run time error "unable to set the locked property of the range class
the code below is highlighted
It would be appreciated if someone could assist me
Code:
Sub ProtectAll()
Dim sht As Worksheet
Dim cel As Range
Dim twb As Workbook
Set twb = ThisWorkbook
For Each sht In twb.Sheets
For Each cel In sht.UsedRange
If cel.HasFormula = True Then
cel.Locked = True
Else
cel.Locked = False
End If
Next cel
sht.Protect "Password"
Next sht
End Sub
However when running the macro, I get a run time error "unable to set the locked property of the range class
the code below is highlighted
Code:
cel.Locked = False
It would be appreciated if someone could assist me