View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Toby Erkson Toby Erkson is offline
external usenet poster
 
Posts: 32
Default How to name a chart for referencing in VBA? And move it. UPDATED.

What's working so far...
Dim chartAvgCalls As Chart
Set chartAvgCalls = Charts.Add
chartAvgCalls.SetSourceData Source:=Sheets("Pivots").Range("B7")
ActiveChart.HasPivotFields = False
With chartAvgCalls
.HasPivotFields = False
.PlotArea.Select
End With
...
Now, this line takes the chart (which is currently it's own sheet) and places it in an existing sheet named "Charts":
ActiveChart.Location whe=xlLocationAsObject, Name:="Charts"
This, too, works. But after that I can't figure out how to select the chart and move it. Using the macro recorder isn't helpful because this is what it
produces:
ActiveSheet.ChartObjects("Chart 62").Activate
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 62").IncrementLeft -168#
ActiveSheet.Shapes("Chart 62").IncrementTop -107.25
Notice that it specifically selects "Chart 62". Well, that chart won't exist the next time this is run because it increments i.e. Chart 63. I need a way to
programmatically specify the selected chart (object?) so I can move it.

Additional info: The "Charts" sheet starts out blank but in the end will have three different charts placed in it -- which is why I need to be able to select
the specific chart currently being created so it can be moved.

Toby Erkson
Oregon, USA