+ Reply to Thread
Results 1 to 3 of 3

Deleting a chart using VBA

  1. #1
    Forum Contributor
    Join Date
    09-08-2005
    Location
    UK
    MS-Off Ver
    2010
    Posts
    107

    Deleting a chart using VBA

    Hi everybody,

    I've created some code to draw up a chart when a button is pressed.
    However, I'm trying to find a way for the macro to first check to see if there is already a chart open on the sheet, and if so then delete it before generating the chart.

    Is this possible?

    Chart code:

    Please Login or Register  to view this content.
    Cheers

  2. #2
    Bernie Deitrick
    Guest

    Re: Deleting a chart using VBA

    Dominic,

    On Error Resume Next
    ActiveSheet.ChartObjects.Delete

    HTH,
    Bernie
    MS Excel MVP


    "Daminc" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi everybody,
    >
    > I've created some code to draw up a chart when a button is pressed.
    > However, I'm trying to find a way for the macro to first check to see
    > if there is already a chart open on the sheet, and if so then delete it
    > before generating the chart.
    >
    > Is this possible?
    >
    > Chart code:
    >
    >
    > Code:
    > --------------------
    > Charts.Add
    > ActiveChart.ChartType = xlColumnClustered
    > ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("G2:J2,G4:J4"), _
    > PlotBy:=xlRows
    > ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    > With ActiveChart
    > .HasTitle = True
    > .ChartTitle.Characters.Text = "Name1"
    > .Axes(xlCategory, xlPrimary).HasTitle = True
    > .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
    > .Axes(xlValue, xlPrimary).HasTitle = True
    > .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
    > "Text"
    > End With
    > ActiveChart.HasLegend = False
    > ActiveChart.HasDataTable = False
    > ActiveChart.Axes(xlValue).Select
    > With ActiveChart.Axes(xlValue)
    > .MinimumScaleIsAuto = True
    > .MaximumScaleIsAuto = True
    > .MinorUnit = 1
    > .MajorUnit = 1
    > .Crosses = xlAutomatic
    > .ReversePlotOrder = False
    > .ScaleType = xlLinear
    > .DisplayUnit = xlNone
    > End With
    > End Sub
    > --------------------
    >
    >
    > Cheers
    >
    >
    > --
    > Daminc
    > ------------------------------------------------------------------------
    > Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
    > View this thread: http://www.excelforum.com/showthread...hreadid=476179
    >




  3. #3
    Forum Contributor
    Join Date
    09-08-2005
    Location
    UK
    MS-Off Ver
    2010
    Posts
    107
    Dominic,

    On Error Resume Next
    ActiveSheet.ChartObjects.Delete

    HTH,
    Bernie
    MS Excel MVP
    Cheers Bernie, is "On Error Resume Next" a standard error trap then?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1