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.
Prevent a certain worksheet from being deleted with VBA code
Prevent a certain worksheet from being deleted with VBA code
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.
Related articles:
- How to prevent specific cell contents from being deleted in Excel?
- How to prevent selection of multiple worksheets in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!