ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating a Graph as an Object : Urgent! (https://www.excelbanter.com/excel-programming/299382-creating-graph-object-urgent.html)

Richard1284[_5_]

Creating a Graph as an Object : Urgent!
 
Hi all,

Could anyone please let me know how I can delete a specific graph on
specific sheet in VBA . I have tried inserting it as an object but thi
doesn't work as I believe it already is an object. I have trie
referring to its TopLeftCell address, I don't think this works and
have also tried the old Workbook.Charts.Delete

Can anyone please help

--
Message posted from http://www.ExcelForum.com


DNF Karran[_13_]

Creating a Graph as an Object : Urgent!
 
Sheets(1).ChartObjects("Chart 2").Delete

will delete a chart- no need to create as an object

--
Message posted from http://www.ExcelForum.com


Richard1284[_6_]

Creating a Graph as an Object : Urgent!
 
This is correct code however it is not adequate. What happens in my ap
is that when the user wishes to see the graph they click on a button
Thus as the graph is being created it gets a name like ("Chart 207"
thus I what I need to do in my app is firstly check if the graph i
there...

if it is then it should be deleted AND additionally I need to know ho
to reference the graph. eg. Because excel comes up with random grap
names I can just hardcode a....

Sheets("Main").ChartObjects("Chart 276").Delete

Because Chart 276 won't always be chart 276.

Thanks for your help initially, do you have any other ideas??

--
Message posted from http://www.ExcelForum.com


DSC[_21_]

Creating a Graph as an Object : Urgent!
 
If you are using only one chart on a page you could use

Worksheets("Main").ChartObjects(1).Delete

This let me clear a chart from my worksheet.

Dont know if this is the proper way to do this but it worked for me.


Davi

--
Message posted from http://www.ExcelForum.com


DNF Karran[_14_]

Creating a Graph as an Object : Urgent!
 
How about when creating the chart assign to object var

sub CreateChart
dim chMyChart

set chMyChart = Charts.Add
....
....


You can then refer to the chart as a variable.

Other options include looping through all the chart objects in a sheet-
something like

Dim chMyChart

For Each chMyChart In ActiveSheet.ChartObjects
.....
Next
....

Duncan


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 12:16 PM.

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