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.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
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?
Recommended Productivity Tools
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.· 7 months 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.· 1 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.