Forum Discussion
lobo114
Oct 24, 2023Brass Contributor
Edit a recorded macro to include an IF statement
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
I don't understand. Your macro starts by deleting the Home sheet, so the rest should always be executed...
- lobo114Brass ContributorI'm not sure why it doesn't work either. What I want to happen is if the user deletes the home sheet, the rest of the macro runs, but nothing happens when I delete the home tab. If I run the macro then the macro deletes the home tab and everything else below it works. I want the macro to work when the home tab is manually deleted.
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