I have a macro that deletes a set of worksheets. Here it is.
I usually create a pivot table named "Sheet6" a few days a week. I'd like to add something to my macro that will check if this worksheet is present and delete it if it is, and do nothing if it isn't.
I'm just not sure of the code to check if the worksheet is present.
Any help would be appreciated!!
Thanks.
---
I found a solution.. thanks though.
Code:
Sub Delete_Worksheets()
'
' Delete_Worksheets Macro
'
' Keyboard Shortcut: Ctrl+Shift+D
'
Sheets(Array("Daily Report", "Region", "Territory", "Revenue - Detail", "Less than or Equal to Zero")).Select
Sheets("Revenue - Detail").Activate
ActiveWindow.SelectedSheets.Delete
End Sub
I usually create a pivot table named "Sheet6" a few days a week. I'd like to add something to my macro that will check if this worksheet is present and delete it if it is, and do nothing if it isn't.
I'm just not sure of the code to check if the worksheet is present.
Any help would be appreciated!!
Thanks.
---
I found a solution.. thanks though.
Code:
'
' Delete_Worksheets Macro
'
' Keyboard Shortcut: Ctrl+Shift+D
'
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets("Sheet6")
If Err = 0 Then
Sheets("Sheet6").Select
ActiveWindow.SelectedSheets.Delete
End If
Sheets(Array("Daily Report", "Region", "Territory", "Revenue - Detail", "Less than or Equal to Zero")).Select
Sheets("Revenue - Detail").Activate
ActiveWindow.SelectedSheets.Delete
End Sub
Last edited: