I've been making excel charts using VBA on a macro, I've done all the requirements I needed but one which is giving me the hardest time...
My problem is that when I make the charts I want to add on the X Axis the names of the series (bars) so it's easier to read, effect that I couldn't replicate with a macro, I'm able to set the series names and get them on the Legend but I can't get it to be on the axis
Ok, so I tried setting the series names like:
ActiveChart.SeriesCollection(k).Name = Range("O180").Value & " " & Range("F86").Value & vbNewLine & "Óptimo: 10-12"
I also tried setting up and XValues but it only accept Arrays, altho I have created a one entry Array but it didn't made what I wanted.
I also make some formating before and after I add all the series Tried:
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
after add
So this is how I add series, I add them all the same, after this begins another If Application.IsNA
to add another serie....
If (Not Application.IsNA(Range("P163").Value)) Then
If (Not Len(Range("P163")) <= 0) Then
z = z + 1
If (ActiveChart.SeriesCollection.Count < z) Then
ActiveChart.SeriesCollection.NewSeries
End If
ActiveChart.SeriesCollection(z).Values = Range("W163").Value
ActiveChart.SeriesCollection(z).Name = Range("O163").Value & " " & Range("F49").Value & vbNewLine & "Óptimo: 6,5-7,0 (Acidez Activa)"
ActiveChart.SeriesCollection(z).Format.Fill.OneColorGradient msoGradientHorizontal, 1, 1
ActiveChart.SeriesCollection(z).Format.Fill.GradientStops(1).Position = 0.25
ActiveChart.SeriesCollection(z).Format.Fill.GradientStops(2).Position = 1
'ActiveChart.SeriesCollection(z).Points(1).AxisGroup = z COMENTED LINE
ActiveChart.SeriesCollection(z).Points(1).ApplyDataLabels
ActiveChart.SeriesCollection(z) _
.DataLabels.ShowSeriesName = True
lastInput(1) = Range("O163").Value 'Name
lastInput(2) = Range("F49").Value 'Unformated Value for Legend
lastInput(3) = Range("W163").Value 'Formated value for chart
lastInput(4) = "Óptimo: 6,5-7,0 (Acidez Activa)" 'Complementary Optimal Legend Entry
End If
End If
I wanted the name on the XAxis bellow the bar, so each bar has its name
I hope this image is understandable, please pay no mind to all the problems the chart in the picture has, only to the one I'm having trouble with...
Values
for a series is most often done using an array. In your code you're only using the value of a single cell to set all the values in the series (Range("W163").Value
). Is that your intention? - PeterT