View Single Post
  #6  
Old June 10th, 2004, 02:08 PM
z.entropic
external usenet poster
 
Posts: n/a
Default macro to create charts in worksheets with arbitrary names

Now you both lost me--how do I use your code if my recorded macro is full of references to the specific name of the renamed active worksheet:

' Keyboard Shortcut: Ctrl+a
'
Range("H2:H10").Select
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Data").Range("H2:H10"), PlotBy:= _
xlColumns
ActiveChart.SeriesCollection(1).Values = "=Data!R2C8:R1000C8"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C9:R1000C9"
ActiveChart.SeriesCollection(1).Name = "=Data!R1C9"
ActiveChart.SeriesCollection(2).XValues = "=Data!R2C10:R1000C10"
ActiveChart.SeriesCollection(2).Values = "=Data!R2C8:R1000C8"
ActiveChart.SeriesCollection(2).Name = "=Data!R1C10"
ActiveChart.Location Whe=xlLocationAsObject, Name:="Data"
With ActiveChart

z.entropic


"Jon Peltier" wrote:

Missed that. Of course, the other solution is to use

ActiveSheet.ChartObjects.Add(L, T, W, H).Select
ActiveChart.SetSourceData Source:=ActiveSheet.Range("G2:H11")

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

Tushar Mehta wrote:

The Charts.Add creates a new chart in its own sheet. ActiveSheet at
that point refers to the newly minted chartsheet!

Use something like the untested:

dim SrcSheet as worksheet, aChart as chart
set srcsheet=activesheet
set achart=charts.add
achart.SetSourceData Source:=srcsheet.Range("G2:H11")
....