Try this VBA
place in a Module
' Why protect every sheet when you might only need to do something with one sheet?
'Sub ProtectSh()
Sub ProtectSh(Optional wSheet As Worksheet)
If wSheet Is Nothing Then
' Best to be clear about which workbook you are protecting:
'For Each wSheet In Worksheets
For Each wSheet In ThisWorkbook.Worksheets
' Adding userinterfaceonly:=true means that your VBA code can do whatever it
' needs to without having to unprotect the sheet first!
'wSheet.Protect Password:="Password"
wSheet.Protect Password:="Password", userinterfaceonly:=True
Next wSheet
Else
wSheet.Protect Password:="Password", userinterfaceonly:=True
End If
End Sub
' Why unprotect every sheet when you might only need to do something with one sheet?
'Sub UnprotectSh()
Sub UnprotectSh(Optional wSheet As Worksheet)
If wSheet Is Nothing Then
For Each wSheet In Worksheets
wSheet.Unprotect Password:="Password"
Next wSheet
Else
wSheet.Unprotect Password:="Password"
End If
End Sub
Then place this in your sheet
Call UnprotectSh
Your Code!!
Call ProtectSh
Bookmarks