delete graph in wbook

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

delete graph in wbook

Post by sal21 »

I use this code to delete a sheet in wbook, but why not work to dlete a sheet with a graph?

Code: Select all

Sub CANELLA_SHEET()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Dim WS As Worksheet
     For Each WS In Worksheets

        If WS.Name = "TEST GRAFICO" Then WS.Delete
        Next
        
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub
Last edited by HansV on 03 Sep 2010, 13:13, edited 1 time in total.
Reason: to correct subject and code tags

User avatar
HansV
Administrator
Posts: 78490
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: delete graph in wbook

Post by HansV »

A chart sheet is not a worksheet. You can look at the Charts collection instead of the Worksheets collection:

Code: Select all

Sub CANELLA_CHART()
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False

  Dim cht As Chart
  For Each cht In Charts
    If cht.Name = "TEST GRAFICO" Then cht.Delete
  Next cht

  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: delete graph in wbook

Post by sal21 »

HansV wrote:A chart sheet is not a worksheet. You can look at the Charts collection instead of the Worksheets collection:

Code: Select all

Sub CANELLA_CHART()
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False

  Dim cht As Chart
  For Each cht In Charts
    If cht.Name = "TEST GRAFICO" Then cht.Delete
  Next cht

  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub
:clapping: :evilgrin: :fanfare:
tks, Sal