I am trying to achieve a simple task in VBA: get a histogram made of different series. As "XValues" I have strings. As "Values" I have floats.
The problem is, that when I add new series to the SeriesCollection of my xlColumnClustered chart, it does not consider the "XValues" and adds the data (columns) automatically from the top left, and the data (columns) of different series mix. This instead of adding the data of the new serie right after the data of the preceding serie.
The code I used is as follows:
Dim MyEmbeddedChart As Chart
Set MyEmbeddedChart = ActiveSheet.Shapes.AddChart.Chart
With MyEmbeddedChart
'Data
.ChartType = xlColumnClustered
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "PTV = CTV + 5mm"
.SeriesCollection(1).XValues = "=" & ActiveSheet.Name & "!" & PAi & ":" & PAf
.SeriesCollection(1).Values = "=" & ActiveSheet.Name & "!" & Ai & ":" & Af
.SeriesCollection.NewSeries
.SeriesCollection(2).Name = "PTV = CTV + 7mm"
.SeriesCollection(2).XValues = "=" & ActiveSheet.Name & "!" & PBi & ":" & PBf
.SeriesCollection(2).Values = "=" & ActiveSheet.Name & "!" & Bi & ":" & Bf
.SeriesCollection.NewSeries
.SeriesCollection(3).Name = "PTV = CTV + ?"
.SeriesCollection(3).XValues = "=" & ActiveSheet.Name & "!" & PCi & ":" & PCf
.SeriesCollection(3).Values = "=" & ActiveSheet.Name & "!" & Ci & ":" & Cf
.SeriesCollection.NewSeries
.SeriesCollection(4).Name = "PTV of pre-treated patients"
.SeriesCollection(4).XValues = "=" & ActiveSheet.Name & "!" & PDi & ":" & PDf
.SeriesCollection(4).Values = "=" & ActiveSheet.Name & "!" & Di & ":" & Df
'Titles
.HasTitle = True
.ChartTitle.Characters.Text = "V95% of CS-PTV(%) (Patients)"
.ChartTitle.Characters(Start:=2, Length:=3).Font.Subscript = True
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Patients"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "V95%(%) of CS-PTV(%)"
.Axes(xlValue, xlPrimary).AxisTitle.Characters(Start:=2, Length:=3).Font.Subscript = True
.Axes(xlCategory).HasMajorGridlines = True
'Formatting
.Axes(xlCategory).HasMinorGridlines = False
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlValue).HasMinorGridlines = True
.HasLegend = True
'Position
.ChartArea.Left = 725
.ChartArea.Top = 70
.ChartArea.Height = 500
.ChartArea.Width = 750
End With
Where the local variables involved in the definition of the different series during the running time are equal to:
The sheet that I am working with and the histogram that I get look like this:
As you can see I don't want the columns belonging to different categories to mix but to appear after an other.
Has somebody an idea how I can get what I want. I thank your very much in advance.