PC Review


Reply
Thread Tools Rate Thread

Deleting Charts

 
 
Ardy
Guest
Posts: n/a
 
      14th Dec 2006
Hello All:
I am creating a chart by ht following code, that is activated via
command button.

Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"
With ActiveChart
.SetSourceData Source:=Sheets("Roster").Range("A2:E5"), PlotBy:= _
xlRows
.HasTitle = True
.ChartType = xlColumnClustered
.HasLegend = False
.SeriesCollection(1).XValues = "=Roster!R2C1:R5C1"
.SeriesCollection(1).Values = "=Roster!R2C4:R5C4"
.SeriesCollection(1).Name = "=Roster!R1C4"
.SeriesCollection(2).Values = "=Roster!R2C5:R5C5"
.SeriesCollection(2).Name = "=Roster!R1C5"
.ChartTitle.Characters.Text = "Concepts About Print"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With

I want to delete this chart via another command Button using this
code, it is not working, Any Idea

Private Sub CommandButton4_Click()
ActiveSheet.ChartObject.Delete
End Sub

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      14th Dec 2006
One way is to create a module level variable to use;
Dim MyChart As Chart

Private Sub CommandButton1_Click()
Set MyChart = Charts.Add
End Sub

Private Sub CommandButton2_Click()
If Not MyChart Is Nothing Then
Application.DisplayAlerts = False
MyChart.Delete
Application.DisplayAlerts = True
Set MyChart = Nothing
End If
End Sub

NickHK

"Ardy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello All:
> I am creating a chart by ht following code, that is activated via
> command button.
>
> Private Sub CommandButton3_Click()
> Application.ScreenUpdating = False
> Charts.Add
> ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"
> With ActiveChart
> .SetSourceData Source:=Sheets("Roster").Range("A2:E5"), PlotBy:= _
> xlRows
> .HasTitle = True
> .ChartType = xlColumnClustered
> .HasLegend = False
> .SeriesCollection(1).XValues = "=Roster!R2C1:R5C1"
> .SeriesCollection(1).Values = "=Roster!R2C4:R5C4"
> .SeriesCollection(1).Name = "=Roster!R1C4"
> .SeriesCollection(2).Values = "=Roster!R2C5:R5C5"
> .SeriesCollection(2).Name = "=Roster!R1C5"
> .ChartTitle.Characters.Text = "Concepts About Print"
> .Axes(xlCategory, xlPrimary).HasTitle = False
> .Axes(xlValue, xlPrimary).HasTitle = False
> End With
>
> I want to delete this chart via another command Button using this
> code, it is not working, Any Idea
>
> Private Sub CommandButton4_Click()
> ActiveSheet.ChartObject.Delete
> End Sub
>



 
Reply With Quote
 
Ardy
Guest
Posts: n/a
 
      14th Dec 2006
Thanks.......

NickHK wrote:
> One way is to create a module level variable to use;
> Dim MyChart As Chart
>
> Private Sub CommandButton1_Click()
> Set MyChart = Charts.Add
> End Sub
>
> Private Sub CommandButton2_Click()
> If Not MyChart Is Nothing Then
> Application.DisplayAlerts = False
> MyChart.Delete
> Application.DisplayAlerts = True
> Set MyChart = Nothing
> End If
> End Sub
>
> NickHK
>
> "Ardy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello All:
> > I am creating a chart by ht following code, that is activated via
> > command button.
> >
> > Private Sub CommandButton3_Click()
> > Application.ScreenUpdating = False
> > Charts.Add
> > ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"
> > With ActiveChart
> > .SetSourceData Source:=Sheets("Roster").Range("A2:E5"), PlotBy:= _
> > xlRows
> > .HasTitle = True
> > .ChartType = xlColumnClustered
> > .HasLegend = False
> > .SeriesCollection(1).XValues = "=Roster!R2C1:R5C1"
> > .SeriesCollection(1).Values = "=Roster!R2C4:R5C4"
> > .SeriesCollection(1).Name = "=Roster!R1C4"
> > .SeriesCollection(2).Values = "=Roster!R2C5:R5C5"
> > .SeriesCollection(2).Name = "=Roster!R1C5"
> > .ChartTitle.Characters.Text = "Concepts About Print"
> > .Axes(xlCategory, xlPrimary).HasTitle = False
> > .Axes(xlValue, xlPrimary).HasTitle = False
> > End With
> >
> > I want to delete this chart via another command Button using this
> > code, it is not working, Any Idea
> >
> > Private Sub CommandButton4_Click()
> > ActiveSheet.ChartObject.Delete
> > End Sub
> >


 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      14th Dec 2006
Ardy's chart is an embedded chart:

>> ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"


This will clear all charts on Roster:

Worksheets("Roster").ChartObjects.Delete

This will delete just the last one created:

Worksheets("Roster").ChartObjects(Worksheets("Roster").ChartObjects.Count).Delete

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> One way is to create a module level variable to use;
> Dim MyChart As Chart
>
> Private Sub CommandButton1_Click()
> Set MyChart = Charts.Add
> End Sub
>
> Private Sub CommandButton2_Click()
> If Not MyChart Is Nothing Then
> Application.DisplayAlerts = False
> MyChart.Delete
> Application.DisplayAlerts = True
> Set MyChart = Nothing
> End If
> End Sub
>
> NickHK
>
> "Ardy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hello All:
>> I am creating a chart by ht following code, that is activated via
>> command button.
>>
>> Private Sub CommandButton3_Click()
>> Application.ScreenUpdating = False
>> Charts.Add
>> ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"
>> With ActiveChart
>> .SetSourceData Source:=Sheets("Roster").Range("A2:E5"), PlotBy:= _
>> xlRows
>> .HasTitle = True
>> .ChartType = xlColumnClustered
>> .HasLegend = False
>> .SeriesCollection(1).XValues = "=Roster!R2C1:R5C1"
>> .SeriesCollection(1).Values = "=Roster!R2C4:R5C4"
>> .SeriesCollection(1).Name = "=Roster!R1C4"
>> .SeriesCollection(2).Values = "=Roster!R2C5:R5C5"
>> .SeriesCollection(2).Name = "=Roster!R1C5"
>> .ChartTitle.Characters.Text = "Concepts About Print"
>> .Axes(xlCategory, xlPrimary).HasTitle = False
>> .Axes(xlValue, xlPrimary).HasTitle = False
>> End With
>>
>> I want to delete this chart via another command Button using this
>> code, it is not working, Any Idea
>>
>> Private Sub CommandButton4_Click()
>> ActiveSheet.ChartObject.Delete
>> End Sub
>>

>
>



 
Reply With Quote
 
Ardy
Guest
Posts: n/a
 
      14th Dec 2006
Thanks Jon,
Works Much Cleaner.
Jon Peltier wrote:
> Ardy's chart is an embedded chart:
>
> >> ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"

>
> This will clear all charts on Roster:
>
> Worksheets("Roster").ChartObjects.Delete
>
> This will delete just the last one created:
>
> Worksheets("Roster").ChartObjects(Worksheets("Roster").ChartObjects.Count).Delete
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> http://PeltierTech.com
> _______
>
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > One way is to create a module level variable to use;
> > Dim MyChart As Chart
> >
> > Private Sub CommandButton1_Click()
> > Set MyChart = Charts.Add
> > End Sub
> >
> > Private Sub CommandButton2_Click()
> > If Not MyChart Is Nothing Then
> > Application.DisplayAlerts = False
> > MyChart.Delete
> > Application.DisplayAlerts = True
> > Set MyChart = Nothing
> > End If
> > End Sub
> >
> > NickHK
> >
> > "Ardy" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Hello All:
> >> I am creating a chart by ht following code, that is activated via
> >> command button.
> >>
> >> Private Sub CommandButton3_Click()
> >> Application.ScreenUpdating = False
> >> Charts.Add
> >> ActiveChart.Location Where:=xlLocationAsObject, Name:="Roster"
> >> With ActiveChart
> >> .SetSourceData Source:=Sheets("Roster").Range("A2:E5"), PlotBy:= _
> >> xlRows
> >> .HasTitle = True
> >> .ChartType = xlColumnClustered
> >> .HasLegend = False
> >> .SeriesCollection(1).XValues = "=Roster!R2C1:R5C1"
> >> .SeriesCollection(1).Values = "=Roster!R2C4:R5C4"
> >> .SeriesCollection(1).Name = "=Roster!R1C4"
> >> .SeriesCollection(2).Values = "=Roster!R2C5:R5C5"
> >> .SeriesCollection(2).Name = "=Roster!R1C5"
> >> .ChartTitle.Characters.Text = "Concepts About Print"
> >> .Axes(xlCategory, xlPrimary).HasTitle = False
> >> .Axes(xlValue, xlPrimary).HasTitle = False
> >> End With
> >>
> >> I want to delete this chart via another command Button using this
> >> code, it is not working, Any Idea
> >>
> >> Private Sub CommandButton4_Click()
> >> ActiveSheet.ChartObject.Delete
> >> End Sub
> >>

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting All charts using VB BrownTing Microsoft Excel Programming 3 12th Jul 2006 04:05 PM
Automatically Confirm Deleting Charts fatfish Microsoft Excel Programming 4 22nd Jul 2004 01:02 PM
Deleting charts maxfoo Microsoft Excel Misc 9 29th May 2004 01:37 AM
Deleting charts maxfoo Microsoft Excel Charting 9 29th May 2004 01:37 AM
Deleting charts on a sheet =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 2 13th May 2004 05:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.