Sub LockSheetWithPassword()
Dim pwd As String
pwd = "LOKITRON"
ActiveSheet.Protect Password:=pwd
End Sub
To use this code, open the Visual Basic Editor (VBE) by pressing
Alt + F11, insert a new module, and paste the code. Then, run the LockSheetWithPassword subroutine by clicking on it and pressing F5 or by going to Run > Run Sub/UserForm in the VBE menu.Note that once a sheet is locked with a password, you will need to enter the correct password to unprotect it. Also, if you forget the password, there is no way to recover it, so be sure to keep a record of the password in a safe place.
