Format Chart Bars with code?

J

John

I have data laid out in 3 columns... date in the first, a number in the
second,and a color (Green, Red, or Blue) in the next. I have a chart with
floating bars and would like them to be the color of the color in column
three. Can I do that with code? Is there a better way?
 
J

John

yea, I was hoping you wouldn't say that... I have made my own candle charts
with multiple series for up/down open/close etc... using that technique. I
was hoping there was an easier way then reworking all those series
 
J

John Mansfield

Would this general example work? It assumes the colors are in column C.
Create a bar chart, activate it, and run the code.

Sub ColorBars()

Dim Rng As Range
Dim Color As Integer

Color = Range("C1").Interior.ColorIndex
Set Pts = ActiveChart.SeriesCollection(1).Points(1)
Pts.Interior.ColorIndex = Color

Color = Range("C2").Interior.ColorIndex
Set Pts = ActiveChart.SeriesCollection(1).Points(2)
Pts.Interior.ColorIndex = Color

Color = Range("C3").Interior.ColorIndex
Set Pts = ActiveChart.SeriesCollection(1).Points(3)
Pts.Interior.ColorIndex = Color

End Sub

-- Can be modified to work more efficiently by looping, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top