For locking to work you have to protect the worksheet, in doing so ALL locked cells will be protected so you have to make sure you clear those first, then use some code like:
Sub CommandButton1_Click()
ActiveCell.EntireRow.Locked = True
ActiveCell.EntireRow.FormulaHidden = False
ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
to lock and protect the cells and
ActiveSheet.Unprotect Password:="password"
to unprotect, since locking is not active unless protected you do not need to unlock unless that is your requirement before protecting again!
Bookmarks