Change VBA to all graphs, not specific one

snowman1976

Board Regular
Joined
Nov 4, 2008
Messages
191
Hello

I have this piece of code that works quite well, it changes the color of the bars based on the values. I now will have many graphs in the same sheet that I want to apply this to. How do I change it so its looking at not just 'mainchart', but instead does it to all the graphs ?



Dim chartIterator As Integer, pointIterator As Integer, _
seriesArray() As Variant


'For chartIterator = 1 To ActiveSheet.ChartObjects.Count
seriesArray = ActiveWorkbook.Sheets("GRAPHS").ChartObjects("MAINCHART"). _
Chart.SeriesCollection(1).Values


For pointIterator = 1 To UBound(seriesArray)


If seriesArray(pointIterator) < 0.95 Then
ActiveWorkbook.Sheets("GRAPHS").ChartObjects("MAINCHART"). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 0, 0)

Else
If seriesArray(pointIterator) < 1 Then
ActiveWorkbook.Sheets("GRAPHS").ChartObjects("MAINCHART"). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(255, 255, 0)

Else
ActiveWorkbook.Sheets("GRAPHS").ChartObjects("MAINCHART"). _
Chart.SeriesCollection(1).Points(pointIterator).Interior.Color = _
RGB(0, 176, 80)
End If
End If
Next pointIterator
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Re: need help - change VBA to all graphs, not specific one

Well all that has to happen is for that code to run again but for the next chart, simple way to do that is copy and paste the code in the editor and then change all references to MainChart to the name of the next chart 'Otherchart' or whatever you have called it.

Repeat until all charts are done.
 
Upvote 0
Re: need help - change VBA to all graphs, not specific one

thanks, I was thinking of doing it that way, but then I would have to update the code each time a chart is added/deleted. I was hoping there would be a way to do this to all the charts regardless of name, etc. to avoid this future problem from happening
 
Upvote 0
Re: need help - change VBA to all graphs, not specific one

First of all, use CODE tags to denote your code, not shrunken 4-point text. Easy way: select the code, and click the "#" above the post editor.

Second, here's how you can reference all those charts:

Code:
For iChart = 1 To ActiveWorkbook.Sheets("GRAPHS").ChartObjects.Count

  seriesArray = ActiveWorkbook.Sheets("GRAPHS").ChartObjects(1).Chart.SeriesCollection(1).Values

  ' ' etc. etc.

Next
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,398
Members
449,222
Latest member
taner zz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top