snowman1976
Board Regular
- Joined
- Nov 4, 2008
- Messages
- 191
I have the following VBA that works well (colors bars based on named ranges). I want to make it smarter and apply it to any graph that starts with the name 'BINCHART'. I need to expand this so I can have multiple graphs that change color based on the set conditions of the named cells green and red. How do I change this so its 'for all charts that start with the name binchart' (I just plan on naming them binchart1, binchart2, etc)
as always any help is appreciated
Sub color_graphs()
Dim chartIteratorX As Integer, pointIteratorX As Integer, _
seriesarrayX() As Variant
seriesarrayX = ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Values
For pointIteratorX = 1 To UBound(seriesarrayX)
If seriesarrayX(pointIteratorX) > Range("red") Then
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(255, 0, 0)
Else
If seriesarrayX(pointIteratorX) <= Range("green") Then
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(0, 176, 80)
Else
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(255, 255, 0)
End If
End If
Next pointIteratorX
End Sub
as always any help is appreciated
Sub color_graphs()
Dim chartIteratorX As Integer, pointIteratorX As Integer, _
seriesarrayX() As Variant
seriesarrayX = ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Values
For pointIteratorX = 1 To UBound(seriesarrayX)
If seriesarrayX(pointIteratorX) > Range("red") Then
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(255, 0, 0)
Else
If seriesarrayX(pointIteratorX) <= Range("green") Then
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(0, 176, 80)
Else
ActiveWorkbook.Sheets("Graphs").ChartObjects("BINCHART"). _
Chart.SeriesCollection(1).Points(pointIteratorX).Interior.Color = _
RGB(255, 255, 0)
End If
End If
Next pointIteratorX
End Sub