Protect Excel Sheet for Manual Input but Allow Programming Inputs
Sheet1.Unprotect "123" Sheet1.Range("A1").Value = "ABC" Sheet1.Protect "123"
Sheet1.Protect Password:="123", UserInterfaceOnly:=True
In the code you will notice that UserInterfaceOnly has been passed as True that does the trick. If you protect a sheet with UserInterfaceOnly as True then Excel allows VBA to write data on the sheet without unprotecting it.
Sub ProtectSheet() Sheet1.Protect Password:="123", UserInterfaceOnly:=True End Sub
Thanks for reading the article, subscribe us to get more VBA tricks.