shellig
Materials
- Jan 17, 2003
- 3
Instead of data labels, I sometimes go in and manually change data point colors based on values in another column (like yield values that are graphed and color changes based on input material lot number). What is annoying about this is if the data range of the graph is changed, the colors that I put in manually are no longer correct.
I am trying to figure out a VBA way to color the data points
Here is my first shot.
I am stuck though. See the ** comments in the code.
I am trying to figure out a VBA way to color the data points
Here is my first shot.
I am stuck though. See the ** comments in the code.
Code:
Sub LoopPoints()
Dim Cht As Chart
Dim i As Integer
Dim j As Integer
Set Cht = ActiveChart
' Set Cht = ActiveSheet.ChartObjects(1).Chart 'If embedded
Pts = Cht.SeriesCollection(1).Points.Count 'Looks at only the first series which is all I need for my application
For i = 1 To Pts
'[B]**What if the first point is not the first row? "i" should be the value of the first row of charted data and Pts = total number of points plus value of first row. I am not sure how to find what the value of the first row of charted data is.[/B]
j = 25 'This is the standard color cycle for charting in excel 25-32, 17-24
If Not (Cells(i, 8).Value = Cells(i + 1, 8).Value) Then '[B]** I get a run time error '1004': Method 'Cells' of object '_Global' failed[/B]
' Data that determines data point color change is in column 8 in this worksheet
j = j + 1
If j = 33 Then
j = 17 'J Cycle from 17 to 32 (standard)
End If
Cht.SeriesCollection(1).Points(i).MarkerBackgroundColorIndex = j
End If
Next i
End Sub