I have some data, which I have charted as a scatter plot. And I would like to iterate over the points on the chart, and programmatically using VBA determine their
- cluster
- budget
- actual
- varaince values
I know I can get (4) variance using the following code, but I am not sure how to get values 1: cluster, 2: budget, 3: actual
Sub t3()
Dim chart As chart
Dim series As series
Dim values As Long
Dim p As Double
Set chart = ActiveChart
Set series = chart.SeriesCollection(1)
p = series.Points.Count
For i = 1 To p
values = series.values(i)
Debug.Print " ", i, values,
Debug.Print ""
Next i
End Sub
Using this information for 1, 2, 3, 4, I will check the cluster, and color the point accordingly A: blue, B, Red, C Green
Then I need to put a legend on the left of the chart with the 3 cluster values and their colors: A: blue, B, Red, C Green
chart
What I want
I chart, colored according to cluster: A, B, or C, where each of A, B, C only appear once in the legend. However the cluster is appearing for each point instead :(
Getting the other values
I'd like to do calculations on each point on the scatter chart, however I am not sure how to get access to the other values (budget and actual), as I am only showing cluster and variance on my chart now.
I simply offset from the start position and stored the values in variables, but I feel there must be a better way of accessing other data in a worksheet to use in a chart? Instead of removing it from the data (when you Select Data >> for the chart, can you hide it and then use it in calculations?
chart.SeriesCollection(2)
,chart.SeriesCollection(3)
and so on... – Mitja Bezenšek