View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob R Bob R is offline
external usenet poster
 
Posts: 2
Default Activechart.SetSourceData Source???

I'm opening a new Excel spreadsheet with CSV data that includes stock
prices. I've created a sample macro here, which is suppose to create
a graph with an overlay of additional data (a 5 day moving average).
I realize this can be done on one chart at the same time, but I'm
using this as an example of something more complex I'm working on.
The trouble is, when I go to open another CSV data file and run the
macro, I get stopped out at the activechart.setsourcedata
source:=Sheets("AAA") <- the name of the csv file.
The range will always be the same. Is there another macro where I can
have a window pop up asking me to select a particular stock symbol
from a folder of data? And how would I change the code to incoporate
that? Here is a sample of the code I have thus far, below:

Sub FivedayMaSample()
'
' FivedayMaSample Macro
' Macro recorded 7/27/2004 by HAL
'

'
Columns("A:A").Select
Selection.NumberFormat = "mm/dd/yy;@"
Range("A1:A25,E1:E25").Select
Range("E1").Activate
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData
Source:=Sheets("AAA").Range("A1:A25,E1:E25"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Close"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasDataTable = False
Sheets("AAA").Select
Range("A1:A25,H1:H25").Select
Range("H1").Activate
Selection.Copy
Sheets("Chart1").Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection.Paste Rowcol:=xlColumns,
SeriesLabels:=True, _
CategoryLabels:=True, Replace:=False, NewSeries:=True
ActiveChart.SeriesCollection(2).Select
Application.CutCopyMode = False
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveChart.PlotArea.Select
End Sub