I'm using Excel 2003 and I'm trying to automate some monthly report charts.
I'd like to run a macro that will get data from several different cells, along the same column, and put them into a 2-type chart, which will be saved in a separate Excel workbook. Then data from cells exactly one row below will be collected, put into a 2-type chart, and then saved into a separate Excel workbook. Repeat for multiple rows of data. The reason it's a 2-type chart is because I want a line graph chart type due to the need for a target line.
Here is an example image of the chart. I've created the chart in Excel but I have no way to upload the picture at work, as all image hosting sites are seemingly blocked:
My chart only has one series though, other than the target series, so it's not as complex as the above.
I've never used Macros in Excel before, and I'm having trouble with them. I've recorded a Macro while going through the process but I'm receiving the following error:
I highlighted the erroneous code in red:
I'm sure there'll be some superfluous data in there, as this is the code directly after I recorded the macro.
Any help would be much appreciated, thanks.
I'd like to run a macro that will get data from several different cells, along the same column, and put them into a 2-type chart, which will be saved in a separate Excel workbook. Then data from cells exactly one row below will be collected, put into a 2-type chart, and then saved into a separate Excel workbook. Repeat for multiple rows of data. The reason it's a 2-type chart is because I want a line graph chart type due to the need for a target line.
Here is an example image of the chart. I've created the chart in Excel but I have no way to upload the picture at work, as all image hosting sites are seemingly blocked:
My chart only has one series though, other than the target series, so it's not as complex as the above.
I've never used Macros in Excel before, and I'm having trouble with them. I've recorded a Macro while going through the process but I'm receiving the following error:
Code:
Run-time error '1004':
Method 'SeriesCollection' of object '_Chart' failed
I highlighted the erroneous code in red:
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded
'
'
Charts.Add
[COLOR=red]ActiveChart.ChartType = xlColumnClustered[/COLOR]
[COLOR=red]ActiveChart.SeriesCollection(1).XValues = _[/COLOR]
[COLOR=red] "=(Sheet1!R42C2,Sheet1!R42C5,Sheet1!R42C8,Sheet1!R42C11,Sheet1!R41C14,Sheet1!R41C14,Sheet1!R42C14)"[/COLOR]
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
Windows("macro thing.xls").SmallScroll Down:=21
ActiveSheet.Shapes("Chart 6").IncrementLeft -8.25
ActiveSheet.Shapes("Chart 6").IncrementTop 476.25
Windows("macro thing.xls").SmallScroll Down:=39
ActiveSheet.Shapes("Chart 6").IncrementLeft -345.75
ActiveSheet.Shapes("Chart 6").IncrementTop 420.75
Windows("macro thing.xls").SmallScroll Down:=12
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=""Conv Rate"""
ActiveChart.SeriesCollection(2).Values = _
"=(Sheet1!R116C9,Sheet1!R117C9,Sheet1!R118C9,Sheet1!R119C9,Sheet1!R120C9)"
ActiveChart.SeriesCollection(2).Name = "=""Target"""
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).ChartType = xlLine
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveChart.ChartArea.Select
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = True
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.Axes(xlCategory, xlSecondary).CategoryType = xlAutomatic
ActiveChart.Axes(xlCategory, xlSecondary).Select
With ActiveChart.Axes(xlCategory, xlSecondary)
.Crosses = xlMaximum
.TickLabelSpacing = 1
.TickMarkSpacing = 1
.AxisBetweenCategories = False
.ReversePlotOrder = False
End With
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlNone
.MinorTickMark = xlNone
.TickLabelPosition = xlNone
End With
ActiveChart.Axes(xlValue, xlSecondary).Select
With ActiveChart.Axes(xlValue, xlSecondary)
.MinimumScaleIsAuto = True
.MaximumScale = 1
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlMaximum
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.PlotArea.Select
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScale = 1
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.Axes(xlValue, xlSecondary).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlNone
.MinorTickMark = xlNone
.TickLabelPosition = xlNone
End With
End Sub
I'm sure there'll be some superfluous data in there, as this is the code directly after I recorded the macro.
Any help would be much appreciated, thanks.
Last edited: