ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to delete a chart using code? (https://www.excelbanter.com/excel-programming/334229-how-delete-chart-using-code.html)

pwermuth[_6_]

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.


--
pwermuth
------------------------------------------------------------------------
pwermuth's Profile: http://www.excelforum.com/member.php...o&userid=24997
View this thread: http://www.excelforum.com/showthread...hreadid=386319


Tom Ogilvy

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" wrote in
message ...

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




Damon Longworth

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" wrote in
message ...

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




pwermuth[_8_]

how to delete a chart using code?
 

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


Damon Longworth

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" wrote in
message ...

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





All times are GMT +1. The time now is 01:43 PM.

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