Showing posts from November, 2019

Delete Target Sheet Automatically if the Target Sheet is Unprotected!

Friend asked me a little query. he wants VBA to delete his Target Sheet automatically if the Target Sheet is Unprotected! Now, that's something easy but it's not! Not at all! unless you know the best way to achieve that task using an available property of the Sheet Object. There's a Sheet property called,."ProtectContents" Here's how you can perform.. Step 1: Choose TargetSheet Step 2: Open Code Editor for that Target Sheet Object from VBE. Step 3: Paste Below Code Private Sub Worksheet_SelectionChange(ByVal Target As Range)     On Error Resume Next     Application.DisplayAlerts = False     If Sheets("SheetName").ProtectContents = False Then         Sheets("SheetName").Delete     End If     Application.DisplayAlerts = True     On Error GoTo 0 End Sub That's it! Now if someone will illegally try to crack your Target Sheet password from your workbook then after any cell selection by the user will trigger the abov