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

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

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

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
How do I graph data daily as a line graph across a calendar format Glani Charts and Charting in Excel 3 November 23rd 07 09:05 AM
Can I make a graph to be a specific size? (actual graph) Jessica Excel Discussion (Misc queries) 0 August 14th 06 08:45 PM
Macro to make a graph: help selecting the data ranges. Isabel Excel Programming 2 March 15th 06 03:33 PM
Hyperlinkage of one graph with another graph or Drill down graph Sanjay Kumar Singh Charts and Charting in Excel 1 January 3rd 06 12:22 PM


All times are GMT +1. The time now is 02:13 PM.

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"