Oct 24 2023 11:13 AM
In the attached document, I have an example of a macro I recorded. I would like to write an IF statement at the beginning to say, if the "Home" sheet is deleted, then run the rest of the macro. Any help would be appreciated! Thanks
Oct 24 2023 02:39 PM
I don't understand. Your macro starts by deleting the Home sheet, so the rest should always be executed...
Oct 24 2023 02:57 PM
Oct 24 2023 03:04 PM
Does this do what you want?
Sub Macro2()
Application.DisplayAlerts = False
On Error Resume Next
workSheets("Home").Delete
On Error GoTo 0
With workSheets("Work Center Template")
.Unprotect
.Shapes("Group 6").Delete
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
With Sheets("SAC Template")
.Unprotect
.Shapes.Range("Group 9").Delete
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
AllowDeletingRows:=True
End With
End Sub
Oct 24 2023 03:21 PM
Oct 25 2023 06:42 AM
Oct 25 2023 06:58 AM
Change the macro to
Sub Macro2()
With workSheets("Work Center Template")
.Unprotect
.Shapes("Group 6").Delete
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
With Sheets("SAC Template")
.Unprotect
.Shapes.Range("Group 9").Delete
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
AllowDeletingRows:=True
End With
End Sub
Double-click ThisWorkbook in the Project Explorer pane on the left.
Copy the following code into the ThisWorkbook module:
Private Sub Workbook_SheetBeforeDelete(ByVal Sh As Object)
If Sh.Name = "Home" Then
Call Macro2
End If
End Sub