+ Reply to Thread
Results 1 to 5 of 5

how to delete a chart using code?

  1. #1
    Registered User
    Join Date
    07-07-2005
    Location
    New York
    Posts
    21

    how to delete a chart using code?

    How do I delete a chart for which I do not have a name but only the cell the chart is anchored in using code?

    I.e. when I created the chart I pasted in in a cell. Now I want to be able to delete it by somehow referring to the cell I pasted it into.

  2. #2
    Tom Ogilvy
    Guest

    Re: how to delete a chart using code?

    if you have multiple charts:

    Dim chartobj as ChartObject
    for each chartobj in ActiveSheet.ChartObjects
    if chartObj.TopLeftCell.Address = "$B$9" then
    chartObj.Delete
    end if
    Next

    If only one
    activesheet.ChartObjects(1).Delete

    --
    Regards,
    Tom Ogilvy

    "pwermuth" <[email protected]> wrote in
    message news:[email protected]...
    >
    > How do I delete a chart for which I do not have a name but only the cell
    > the chart is anchored in using code?
    >
    > I.e. when I created the chart I pasted in in a cell. Now I want to be
    > able to delete it by somehow referring to the cell I pasted it into.
    >
    >
    > --
    > pwermuth
    > ------------------------------------------------------------------------
    > pwermuth's Profile:

    http://www.excelforum.com/member.php...o&userid=24997
    > View this thread: http://www.excelforum.com/showthread...hreadid=386319
    >




  3. #3
    Damon Longworth
    Guest

    Re: how to delete a chart using code?

    You do not say if there are multiple charts, but if only one:

    ActiveSheet.ChartObjects(1).Delete

    If there are multiple charts, the simplest method is to name the chart upon
    creation. With the name, it is easy to refer to the object later.

    ActiveSheet.ChartObjects(1).Name = "YourChart"

    --
    Damon Longworth

    Don't miss out on the 2005 Excel User Conference
    Sept 16th and 17th
    Stockyards Hotel - Ft. Worth, Texas
    www.ExcelUserConference.com


    "pwermuth" <[email protected]> wrote in
    message news:[email protected]...
    >
    > How do I delete a chart for which I do not have a name but only the cell
    > the chart is anchored in using code?
    >
    > I.e. when I created the chart I pasted in in a cell. Now I want to be
    > able to delete it by somehow referring to the cell I pasted it into.
    >
    >
    > --
    > pwermuth
    > ------------------------------------------------------------------------
    > pwermuth's Profile:
    > http://www.excelforum.com/member.php...o&userid=24997
    > View this thread: http://www.excelforum.com/showthread...hreadid=386319
    >




  4. #4
    Registered User
    Join Date
    07-07-2005
    Location
    New York
    Posts
    21
    Thank you for your help.

    The reason I did not name charts is that I am creating 50-100 at a time and then I do not touch them again in the same Macro. The Macro that is supposed to deleted them is a cleaning Macro so I do not see a way to pass the names of the charts to that Macro.

  5. #5
    Damon Longworth
    Guest

    Re: how to delete a chart using code?

    I do not know your process, but you could name all charts that will be
    deleted with a similar prefix. Something similar to:

    DelChart1

    Then you could delete all charts that begin with "Del".

    --
    Damon Longworth

    Don't miss out on the 2005 Excel User Conference
    Sept 16th and 17th
    Stockyards Hotel - Ft. Worth, Texas
    www.ExcelUserConference.com


    "pwermuth" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thank you for your help.
    >
    > The reason I did not name charts is that I am creating 50-100 at a time
    > and then I do not touch them again in the same Macro. The Macro that is
    > supposed to deleted them is a cleaning Macro so I do not see a way to
    > pass the names of the charts to that Macro.
    >
    >
    > --
    > pwermuth
    > ------------------------------------------------------------------------
    > pwermuth's Profile:
    > http://www.excelforum.com/member.php...o&userid=24997
    > View this thread: http://www.excelforum.com/showthread...hreadid=386319
    >




+ 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