• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Needs some help in Macro for Excel 2010[solved]

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Lukee

Member
Joined
Jun 8, 2008
Location
Miami, FL
I have a macro that deletes a set of worksheets. Here it is.

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:
Back