Hi, I have this VBA code to generate multiple line charts on a few pages. Overlaid on the data lines on each chart are two vertical lines that mark two x-axis dates consistent among all the charts. The charts look fine when they're produced but when I copy and paste them (no matter the format) the two vertical lines go away. Perhaps the x-axis min and max need to be explicitly stated for the vertical lines? This was the case for the data lines themselves. But I don't see how to do this for the vertical lines. Can anyone help?
Thanks!
_________________
chartplace = 25
For chartcount = 1998 To 2013 Step 1
If chartcount = 2012 Then chartcount = chartcount + 1
Sheets("wtchart").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("wt " & CStr(chartcount) & " array").Range("B5:B118,D5:D118")
' The first series to add is number 2; each subsequent series adds 1
seriescount = 2
' The first series to add is in column 6; subsequent series are in every other column
' The last column in the array sheet is column "GO", which is column number 197.
For colcount = 6 To 197 Step 2
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).Name = "='wt " & CStr(chartcount) & " array'!r5c" & colcount
ActiveChart.SeriesCollection(seriescount).Values = "='wt " & CStr(chartcount) & " array'!r6c" & colcount & ":r118c" & colcount
seriescount = seriescount + 1
Next colcount
'adds vertical lines:
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).ChartType = xlXYScatterLinesNoMarkers
Sheets("wg_cht_dummy_data").Range("A5:D5") = Array("=NA()", 0, 130, "=NA()")
Sheets("wg_cht_dummy_data").Range("A6:D6") = Array("10jun" & chartcount, "18aug" & chartcount, "18aug" & chartcount, "15sep" & chartcount)
ActiveChart.SeriesCollection(seriescount).Values = Sheets("wg_cht_dummy_data").Range("A5:D5")
ActiveChart.SeriesCollection(seriescount).XValues = Sheets("wg_cht_dummy_data").Range("A6:D6")
ActiveChart.SeriesCollection(seriescount).AxisGroup = 1
seriescount = seriescount + 1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).ChartType = xlXYScatterLinesNoMarkers
Sheets("wg_cht_dummy_data").Range("A7:D7") = Array("=NA()", 0, 130, "=NA()")
Sheets("wg_cht_dummy_data").Range("A8:D8") = Array("10jun" & chartcount, "28aug" & chartcount, "28aug" & chartcount, "15sep" & chartcount)
ActiveChart.SeriesCollection(seriescount).Values = Sheets("wg_cht_dummy_data").Range("A7:D7")
ActiveChart.SeriesCollection(seriescount).XValues = Sheets("wg_cht_dummy_data").Range("A8:D8")
ActiveChart.SeriesCollection(seriescount).AxisGroup = 1
'end add vertical lines
With ActiveChart.Parent
.Top = chartplace
.Left = 275
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Font.Size = 6
.ChartTitle.Text = chartcount
.HasLegend = False
.Axes(xlCategory).MajorUnit = 3
.Axes(xlCategory).TickLabelPosition = xlNone
.Axes(xlCategory).TickLabels.Font.Size = 5
.Axes(xlCategory).TickLabels.Font.Name = "Arial"
.Axes(xlCategory).TickLabels.NumberFormat = "[$-409]d-mmm-yy;@"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
.Axes(xlValue).TickLabels.Font.Size = 6
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 130
.Axes(xlCategory).MinimumScale = "10Jun" & chartcount
.Axes(xlCategory).MaximumScale = "15Sep" & chartcount
.Axes(xlValue).MajorUnit = 10
.ChartArea.Width = 225
.ChartArea.Height = 125
.PlotArea.Top = 20
.PlotArea.Height = 110
.PlotArea.Width = 220
End With
chartplace = chartplace + 125
Next chartcount
With ActiveChart
.Axes(xlCategory).TickLabelPosition = xlNextToAxis
End With
End Sub
Thanks!
_________________
chartplace = 25
For chartcount = 1998 To 2013 Step 1
If chartcount = 2012 Then chartcount = chartcount + 1
Sheets("wtchart").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("wt " & CStr(chartcount) & " array").Range("B5:B118,D5:D118")
' The first series to add is number 2; each subsequent series adds 1
seriescount = 2
' The first series to add is in column 6; subsequent series are in every other column
' The last column in the array sheet is column "GO", which is column number 197.
For colcount = 6 To 197 Step 2
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).Name = "='wt " & CStr(chartcount) & " array'!r5c" & colcount
ActiveChart.SeriesCollection(seriescount).Values = "='wt " & CStr(chartcount) & " array'!r6c" & colcount & ":r118c" & colcount
seriescount = seriescount + 1
Next colcount
'adds vertical lines:
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).ChartType = xlXYScatterLinesNoMarkers
Sheets("wg_cht_dummy_data").Range("A5:D5") = Array("=NA()", 0, 130, "=NA()")
Sheets("wg_cht_dummy_data").Range("A6:D6") = Array("10jun" & chartcount, "18aug" & chartcount, "18aug" & chartcount, "15sep" & chartcount)
ActiveChart.SeriesCollection(seriescount).Values = Sheets("wg_cht_dummy_data").Range("A5:D5")
ActiveChart.SeriesCollection(seriescount).XValues = Sheets("wg_cht_dummy_data").Range("A6:D6")
ActiveChart.SeriesCollection(seriescount).AxisGroup = 1
seriescount = seriescount + 1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriescount).ChartType = xlXYScatterLinesNoMarkers
Sheets("wg_cht_dummy_data").Range("A7:D7") = Array("=NA()", 0, 130, "=NA()")
Sheets("wg_cht_dummy_data").Range("A8:D8") = Array("10jun" & chartcount, "28aug" & chartcount, "28aug" & chartcount, "15sep" & chartcount)
ActiveChart.SeriesCollection(seriescount).Values = Sheets("wg_cht_dummy_data").Range("A7:D7")
ActiveChart.SeriesCollection(seriescount).XValues = Sheets("wg_cht_dummy_data").Range("A8:D8")
ActiveChart.SeriesCollection(seriescount).AxisGroup = 1
'end add vertical lines
With ActiveChart.Parent
.Top = chartplace
.Left = 275
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Font.Size = 6
.ChartTitle.Text = chartcount
.HasLegend = False
.Axes(xlCategory).MajorUnit = 3
.Axes(xlCategory).TickLabelPosition = xlNone
.Axes(xlCategory).TickLabels.Font.Size = 5
.Axes(xlCategory).TickLabels.Font.Name = "Arial"
.Axes(xlCategory).TickLabels.NumberFormat = "[$-409]d-mmm-yy;@"
.Axes(xlCategory).TickLabels.Orientation = xlUpward
.Axes(xlValue).TickLabels.Font.Size = 6
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 130
.Axes(xlCategory).MinimumScale = "10Jun" & chartcount
.Axes(xlCategory).MaximumScale = "15Sep" & chartcount
.Axes(xlValue).MajorUnit = 10
.ChartArea.Width = 225
.ChartArea.Height = 125
.PlotArea.Top = 20
.PlotArea.Height = 110
.PlotArea.Width = 220
End With
chartplace = chartplace + 125
Next chartcount
With ActiveChart
.Axes(xlCategory).TickLabelPosition = xlNextToAxis
End With
End Sub