I am trying to lock cells only if data has been entered. I want to check the range to make sure that the cells are blank prior to locking them. The error I am getting is "Unable to set Locked property of the Range class". Sheet is not protected and there are no merged cells either.
Sub Locking()
'Lock Cells if data has been entered
Dim rpcell As Range
Set rpcell = Range("F2:G26")
With ActiveSheet
.Unprotect Password:="1234"
.Cells.Locked = False
For Each rpcell In ActiveSheet.UsedRange
If rpcell.Value = "" Then
rpcell.Locked = False
Else
rpcell.Locked = True
End If
Next rpcell
.Protect Password:="1234"
End With
End Sub
For Each rpcell In ActiveSheet.UsedRange
will apply the activesheet as the parent. – Scott CranerRange("F2:G26")
? I think that is your issue – urdearboySet rpcell = Range("F2:G26")
is immediately overwritten withFor Each rpcell In ActiveSheet.UsedRange
So it will look at all cells in the used range and not justF2:G26
. – Scott CranerF2:G26
then useFor Each rpcell In ActiveSheet.Range("F2:G26")
– Scott Craner