I have a macro that I´ve been using to label series data points on a chart with a desired name rather than with the coordinate points. The macro works very well except for one thing, it is only meant to make one series. I would like to add a loop to it to make it be able to plot multiple series and label their data points. I´m not sure if this would work but ideally I would like to have the code distinguish a new series whenever there is a blank row in the data.
So for example:
AG32 4 5
BC78 3 6
HA23 2 0
AN32 4 6
JK12 2 6
I would like the code to creat two series one with AG32-HA23 with labeled data points and one with AN32-JK12 with labeled data points, and on the same graph.
The code I have looks like this:
Sub AttachLabelsToPoints()
'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String
' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False
'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula
'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop
'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).HasDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).DataLabel.Text = _
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter
End Sub
I think I could add series with an outer loop to the format routine that looks something like
For series =1 to n
For each element in series n to number of elements in the series
...
Next element
Next series
but I really don´t know the syntax of VBA at all and I´m honestly not a programmer. Could anyone show me how to do this and repost the edited code?
Thanks
Bookmarks