Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing bar colors in bar graph

I've created a VBA for Excel 2007 program that automatically creates bar graphs for ROI based on up to 52 different tabs in the active workbook. I'm close to done, and the only thing I cannot figure out is how to change the colors of the bargraphs.

The graphs are created in their own subfunction, called with a call like so. Every variable changes around whenever it's called.

Call AddChartObject(1, 1, "Example", extraWeeks, weekDifference)

My sub that it calls looks like this.

Sub AddChartObject(j As Integer, k As Integer, passedChartTitle As String, xtraWks As Integer, ttlWks As Integer)

    Dim topOfChart As Integer

    topOfChart = 25 + (350 * j)

    'Adds bar chart for total sales

    With ActiveSheet.ChartObjects.Add(Left:=375, Width:=475, Top:=topOfChart, Height:=325)
        .Chart.SetSourceData Source:=Sheets("Consolidation").Range("$A$" & 3 + ((17 + xtraWks) _
            * j) & ":$C$" & (4 + ttlWks) + ((17 + xtraWks) * k))
        .Chart.ChartType = xl3DColumnClustered
        .Chart.SetElement (msoElementDataLabelShow)
        .Chart.HasTitle = True
        .Chart.ChartTitle.Text = passedChartTitle & " Sales"
        .Chart.SetElement (msoElementLegendBottom)
        .Chart.SetElement (msoElementDataLabelNone)
        .Chart.RightAngleAxes = True
    End With

End Sub

The RGB color I want to use on the SECOND series in the bar chart is (155, 187, 89), per marketing's wishes. I'm pretty sure there is a .chart.????.???? = RGB (155, 187, 89) command I can use in my With to set this, but I have spent far too much time trying to figure it out, only to come up with nothing.

like image 250
ScottyStyles Avatar asked Apr 11 '11 17:04

ScottyStyles


People also ask

How do you change the color of a bar graph based on value?

Select the bar chart or column chart, then click Kutools > Charts > Color Chart by Value. Then in the popped-out dialog, set the value range and the relative color as you need.

Can we Colour bar graph?

Uniform color using RGBYou can change the color of bars in a barplot using color argument. RGB is a way of making colors. You have to to provide an amount of red, green, blue, and the transparency value to the color argument and it returns a color.

How do I change the color of a bar graph in pages?

Select a data series. Click Color . Pick an option to set the color of the bars. Select Left axis or Right axis to move the axis labels.


1 Answers

Have you tried

.Chart.SeriesCollection([index]).Interior.Color = RGB(155, 187, 89)

(where [index] is a placeholder for the series you want to change the color for)?

like image 191
Jubbles Avatar answered Nov 02 '22 06:11

Jubbles