ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA chart problem (https://www.excelbanter.com/excel-programming/400625-vba-chart-problem.html)

[email protected]

VBA chart problem
 
I have a Excel app that is supposed to include a chart. The data
consists of three columns; a month number, a cumulative projected
budget and cumulative actual expenditures

1 2000 1982
2 4000 4023
3 7000 6995
4 8000
5 11000
6 11500

I am trying to make a chart with two series; one will be the projected
budget, the other the actual expenditures. The actual line should
track the projected line for whatever actual data exists then the
projected line should continue through its data points.

This is the code I wrote trying to generate this chart:

Worksheets("PR Cashflow").Activate
Set crt = ActiveSheet.ChartObjects.Add(475, 40, 520, 300)
crt.Chart.ChartType = xlLineMarkersStacked
crt.Chart.PlotBy = xlColumns

With crt.Chart.SeriesCollection.NewSeries
.Values = ActiveSheet.range("AB5:AB13")
.XValues = ActiveSheet.range("AA5:AA13")
End With

With crt.Chart.SeriesCollection.NewSeries
.Values = ActiveSheet.range("AC5:AC8")
.XValues = ActiveSheet.range("AA5:AA13")
End With

Here is the problem I am having: when it adds the second series to the
chart it appears as though the y axis values are getting added so
instead of the first data points being 1,2000 and 1,1982 it looks like
they are 1,2000 and 1,3982

What am I missing here?


[email protected]

VBA chart problem
 
On Nov 5, 4:30 pm, " wrote:
I have a Excel app that is supposed to include a chart. The data
consists of three columns; a month number, a cumulative projected
budget and cumulative actual expenditures

1 2000 1982
2 4000 4023
3 7000 6995
4 8000
5 11000
6 11500

I am trying to make a chart with two series; one will be the projected
budget, the other the actual expenditures. The actual line should
track the projected line for whatever actual data exists then the
projected line should continue through its data points.

This is the code I wrote trying to generate this chart:

Worksheets("PR Cashflow").Activate
Set crt = ActiveSheet.ChartObjects.Add(475, 40, 520, 300)
crt.Chart.ChartType = xlLineMarkersStacked
crt.Chart.PlotBy = xlColumns

With crt.Chart.SeriesCollection.NewSeries
.Values = ActiveSheet.range("AB5:AB13")
.XValues = ActiveSheet.range("AA5:AA13")
End With

With crt.Chart.SeriesCollection.NewSeries
.Values = ActiveSheet.range("AC5:AC8")
.XValues = ActiveSheet.range("AA5:AA13")
End With

Here is the problem I am having: when it adds the second series to the
chart it appears as though the y axis values are getting added so
instead of the first data points being 1,2000 and 1,1982 it looks like
they are 1,2000 and 1,3982

What am I missing here?


I was missing this: crt.Chart.ChartType = xlLineMarkersStacked

It should have been xlLineMarkers

Doh!



All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com