Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete code chrisnsmith Excel Discussion (Misc queries) 4 March 8th 09 01:10 AM
Delete an autostart Sub with code Tempy Excel Programming 6 June 14th 04 08:20 PM
Ron de Bruins Delete Row Code Q John Excel Programming 0 June 8th 04 11:16 PM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM
VBA code to delete VBA code in another Workbook Chip Pearson Excel Programming 0 September 15th 03 03:54 PM


All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"