ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating Second Chart via Sub Procedure Error (https://www.excelbanter.com/excel-programming/344080-creating-second-chart-via-sub-procedure-error.html)

[email protected]

Creating Second Chart via Sub Procedure Error
 
Hi,

I have a set of data (date, price) for a number (the actual number
depends on the user input from a previous form) of bonds, and I plot
this, via VBA on a single chart, with multiple series.

I then normalise this data, and then plot the normalised data on
another chart. All in the same workbook. I therefore created a
sub-procedure to create the graphs. Part code is below:

'Previous code reads in data from Db and creates 2 worksheets
'One with standard data, the other with Normalised.
'Then the Code calls the sub to create the charts.
Call MakeGraphs("MultiPriceActual", "BondData", lngRowCheck)
Call MakeGraphs("MultiPriceNormalised", "Normalised", lngRowCheck)

'Sub that creates the chart, and adds the series of data for
'plotting.
Sub MakeGraphs(strChtTab As String, strWks As String, intRef As Long)

Dim cht As Chart
Dim i As Integer, intj As Integer

Set cht = ActiveWorkbook.Charts.Add
cht.ChartType = xlLine
cht.Name = strChtTab

cht.HasLegend = True
cht.Legend.Position = xlLegendPositionTop
cht.HasTitle = False
'more code that does the series adding and formatting.

Basically what happens is the first call works well, the chart is
created, and the series plotted. On the second call, the chartsheet is
created, but not filled with a 'skeleton' chart (it is blank), so when
the .haslengend property is set, the code falls down, as there is no
chart to set the property for.

I am sure i am missing something basic here, and can post more code if
required.

Many Thanks
Ian R



All times are GMT +1. The time now is 12:09 AM.

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