madhuchelliah
Board Regular
- Joined
- Nov 22, 2017
- Messages
- 226
- Office Version
- 2019
- Platform
- Windows
Hey guys, how to lock(protect) unused cells in a sheet using macro.Sheet data will be dynamic.Thank you.
Last edited:
Sub MyProtectMacro()
Dim lRow As Long
' Use column C to find last row
lRow = Cells(Rows.Count, "C").End(xlUp).Row
' Unprotect columns C-I down to last row
Range("C1:I" & lRow).Locked = False
' Protect sheet with password
ActiveSheet.Protect Password:="pass"
End Sub
Sub MyProtectMacro()
Dim lRow As Long
[COLOR=#ff0000]' Make sure all cells are locked to start
Cells.Locked = True[/COLOR]
' Use column C to find last row
lRow = Cells(Rows.Count, "C").End(xlUp).Row
' Unprotect columns C-I down to last row
Range("C1:I" & lRow).Locked = False
' Protect sheet with password
ActiveSheet.Protect Password:="pass"
End Sub
I don't see how that is possible.All the cells are locked only. The cells after I columns are locked. The cells below the last used row and column A and B are not locked.