Deleting every chart sheet

Pokman

New Member
Joined
Jul 3, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi guys, I have this little VBA code which deleted all my worksheet except those I listed there. My question is how to make this delete the chart sheets too. I have some sheets which is only a chart, VBA sees it as chart but I want to delete those too.
 

Attachments

  • Névtelen.png
    Névtelen.png
    12.5 KB · Views: 22

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the MrExcel Message Board!

First, change the declaration of the xWs variable to be Object instead of Worksheet.
Then use the Application.ActiveWorkbook.Sheets instead of Application.ActiveWorkbook.Worksheets.

A standalone chart is not a Worksheet, however, it is a subclass of Sheet which is also a superclass of a Worksheet. So, both object types will be processed in the loop when you use Application.ActiveWorkbook.Sheets.

(I moved your question from the MrExcel Books forum to here. Please ask your future Excel questions in the Excel Questions forum, and other related questions in the corresponding question forum).
 
Upvote 0
Solution
In general, like this:

VBA Code:
    Dim oSheet As Object

    For Each oSheet In ActiveWorkbook.Sheets
        Debug.Print oSheet.Name
        '
        '  code here
        '
    Next oSheet


(Tip: when posting code, please try to use 'code tags' to format the code as I have done above
it makes the code easier to read.)
 
Upvote 0

Forum statistics

Threads
1,223,957
Messages
6,175,622
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top