ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   selecting graph (https://www.excelbanter.com/excel-programming/374641-selecting-graph.html)

violet

selecting graph
 
i need to create a graph for the person that is selected by the user. i able
to code till it add the chart..however i gt a problem is that when i run the
macro again, it will have an error unless i manually delete the graph that
has been generated before running the macro again.following is my code. i was
wondering am i able to code in a way that everytime i run tis macro, if there
is a chart on the sheet, it will delete the chart first before creating
another chart.


Worksheets("Graph").Activate
reqcol = Asc("A") + lastcol - 2
strreqcol = Chr(reqcol)
strreqcol = strreqcol & endrow + 1
Range("B1:" & strreqcol).Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Graph").Range("B1:" &
strreqcol), PlotBy:= _
xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Graph"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = strselected
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With


Tom Ogilvy

selecting graph
 

Dim cObj as ChartObject
for each cObj in Activesheet.ChartObjects
cObj.Delete
Next
' remainder of your code.

--
Regards,
Tom Ogilvy


"violet" wrote:

i need to create a graph for the person that is selected by the user. i able
to code till it add the chart..however i gt a problem is that when i run the
macro again, it will have an error unless i manually delete the graph that
has been generated before running the macro again.following is my code. i was
wondering am i able to code in a way that everytime i run tis macro, if there
is a chart on the sheet, it will delete the chart first before creating
another chart.


Worksheets("Graph").Activate
reqcol = Asc("A") + lastcol - 2
strreqcol = Chr(reqcol)
strreqcol = strreqcol & endrow + 1
Range("B1:" & strreqcol).Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Graph").Range("B1:" &
strreqcol), PlotBy:= _
xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Graph"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = strselected
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With


violet

selecting graph
 
thanks so much..it work great...

"Tom Ogilvy" wrote:


Dim cObj as ChartObject
for each cObj in Activesheet.ChartObjects
cObj.Delete
Next
' remainder of your code.

--
Regards,
Tom Ogilvy


"violet" wrote:

i need to create a graph for the person that is selected by the user. i able
to code till it add the chart..however i gt a problem is that when i run the
macro again, it will have an error unless i manually delete the graph that
has been generated before running the macro again.following is my code. i was
wondering am i able to code in a way that everytime i run tis macro, if there
is a chart on the sheet, it will delete the chart first before creating
another chart.


Worksheets("Graph").Activate
reqcol = Asc("A") + lastcol - 2
strreqcol = Chr(reqcol)
strreqcol = strreqcol & endrow + 1
Range("B1:" & strreqcol).Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Graph").Range("B1:" &
strreqcol), PlotBy:= _
xlRows
ActiveChart.Location Whe=xlLocationAsObject, Name:="Graph"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = strselected
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With



All times are GMT +1. The time now is 02:52 AM.

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