Hi, I'm having an issue where by the charts I am adding in VBA are occasionally formatting incorrectly.
I think the issue is being caused when the chart is initially added, as excel kindly guesses the information I would like to include, and makes multiple series.
Is there a way to prevent it from doing this?
Here is my code below
Where ws represents a worksheet. Weekstart is the first column in the dataset, weekend is the last, and ComboBox2.ListIndex + 1 is the row to look in - all these numbers come out as expected.
I think the issue is being caused when the chart is initially added, as excel kindly guesses the information I would like to include, and makes multiple series.
Is there a way to prevent it from doing this?
Here is my code below
Code:
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=ws7.Range(ws7.Cells(ComboBox2.ListIndex + 1, weekstart + 2), ws7.Cells(ComboBox2.ListIndex + 1, weekend + 2))
ActiveChart.SeriesCollection(1).Name = "=""Resolved % (Cumulative)"""
ActiveChart.SeriesCollection(1).XValues = ws7.Range(ws7.Cells(1, weekstart + 2), ws7.Cells(1, weekend + 2))
ActiveChart.Axes(xlCategory).CategoryType = xlCategoryScale
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Values = ws5.Range(ws5.Cells(ComboBox2.ListIndex + 1, weekstart + 2), ws5.Cells(ComboBox2.ListIndex + 1, weekend + 2))
ActiveChart.SeriesCollection(2).Name = "=""Responses"""
ActiveChart.SeriesCollection(2).ChartType = xlColumnClustered
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveChart.ChartTitle.Text = "Responses"
ActiveChart.Parent.Name = "Chart2"
ActiveChart.Axes(xlValue).MaximumScale = 1
With ws1.ChartObjects("Chart2")
.Top = ws1.Range("K13").Top
.Left = ws1.Range("K13").Left
.Width = ws1.Range("K13").Width * 7
.Height = ws1.Range("K13").Heigth * 15
End With
Where ws represents a worksheet. Weekstart is the first column in the dataset, weekend is the last, and ComboBox2.ListIndex + 1 is the row to look in - all these numbers come out as expected.