ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using VBA to Delete a Chart (https://www.excelbanter.com/excel-programming/279451-using-vba-delete-chart.html)

MikeM[_2_]

Using VBA to Delete a Chart
 
Suppose I create a chart with

Charts.Add
set thisChart = ActiveChart

Why can't I delete it with

thisChart.Delete?



Don Guillett[_4_]

Using VBA to Delete a Chart
 
Macro just recorded
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 10/13/2003 by Don Guillett
'

'
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
ActiveWindow.WindowState = xlNormal
ActiveWindow.WindowState = xlMaximized
End Sub



"MikeM" wrote in message
...
Suppose I create a chart with

Charts.Add
set thisChart = ActiveChart

Why can't I delete it with

thisChart.Delete?





Vasant Nanavati

Using VBA to Delete a Chart
 
Hi:

This worked fine for me:

Sub Test()
Dim thisChart As Chart
Charts.Add
Set thisChart = ActiveChart
thisChart.Delete
End Sub

I did get an alert before the deletion, but that is easily suppressed using
the DisplayAlerts property of the Application object.

Regards,

Vasant.


"MikeM" wrote in message
...
Suppose I create a chart with

Charts.Add
set thisChart = ActiveChart

Why can't I delete it with

thisChart.Delete?





Tom Ogilvy

Using VBA to Delete a Chart
 
Sub MakeandBreak()
Charts.Add
Set thisChart = ActiveChart
thisChart.Delete

End Sub

worked fine for me. Prompted if I wanted to delete the chart

Sub MakeandBreak()
Charts.Add
Set thisChart = ActiveChart
Application.DisplayAlerts = False
thisChart.Delete
Application.DisplayAlerts = True
End Sub

that said, this works because ThisChart is visible to the procedure where I
delete it. I suspect that is not your case. You need to declare thischart
as a public variable - do it at the top of a general module outside any
procedure

Public thisChart as Chart

Sub CreateChart
Charts.Add
Set thisChart = ActiveChart
End Sub

Sub deleteChart
Application.DisplayAlerts = False
thisChart.Delete
Application.DisplayAlerts = True
End Sub

that should work.

--
Regards,
Tom Ogilvy




MikeM wrote in message
...
Suppose I create a chart with

Charts.Add
set thisChart = ActiveChart

Why can't I delete it with

thisChart.Delete?






All times are GMT +1. The time now is 06:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com