- To post as a guest, your comment is unpublished.· 1 years agoMate.., it is more for ACCIDENTAL DELETION.
How to prevent a certain worksheet from being deleted in Excel?
If you want to prevent a certain worksheet from being deleted in Excel, please try the method in this article.
The below VBA code can help you to prevent a certain worksheet from being deleted in Excel. Please do as follows.
1. Open the worksheet you don’t want it to be deleted, right click the sheet tab and click View Code from the right-clicking menu.
2. In the Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the Code window.
VBA code: Prevent a certain worksheet from being deleted in Excel
Private Sub Worksheet_Activate() ThisWorkbook.Protect "yourpassword" End Sub Private Sub Worksheet_Deactivate() ThisWorkbook.Unprotect "yourpassword" End Sub
Note: In the code, please replace the content “yourpassword” with your real password.
3. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.
4. Shift to another worksheet and go back to this worksheet again to activate the VBA code.
5. Right click the sheet tab, you can see the Delete option is gray and disabled among the options as below screenshot shown.
- How to prevent specific cell contents from being deleted in Excel?
- How to prevent selection of multiple worksheets in Excel?
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 2 years agohmm.. but after you do that everyone can still click on "view code" and see the password. what is the password for? how can you delete the sheet using the password?
- To post as a guest, your comment is unpublished.· 2 years agoThis does not prevent worksheet deletion. Add an extra sheet, select the new sheet as the primary, the "protected" sheet as a secondary selection and delete. Bye-bye "protected" sheet.