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.
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.
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
>
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
>
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.
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
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks