Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - changing a column colour on a chart 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
I generate a chart (xlColumnClustered) on a fresh worksheet in Excel. I then want to check if any of Y-Axis values are over 100. If a column is over 100 then I want to change the colour of that particular column to red. I can identify which value needs to be changed using the code below but how do I get direct access to a particular column and does it have its own colour/color property?

Code:
  Dim yValues
  Dim i As Integer
  Dim counter As Integer

  yValues = ActiveChart.SeriesCollection(1).Values
  counter = 0
  For i = 1 To UBound(yValues)
    If yValues(i) > 100 Then
      counter = counter + 1
      MsgBox counter
      
    End If
  Next i
Clive [infinity]
 
You need to use the points collection of the seriescollection object
Got this from recording:

ActiveChart.SeriesCollection(1).Points(3).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

Therefore, with your code
Dim yValues
Dim i As Integer
Dim counter As Integer

yValues = ActiveChart.SeriesCollection(1).Values
counter = 0
For i = 1 To UBound(yValues)
If yValues(i) > 100 Then
with activechart.seriescollection(1).points(i)
.interior.colorindex = 3
end with
counter = counter + 1
MsgBox counter

End If
Next i

HTH Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top