VBA Chart Help

Spartan920

New Member
Joined
Sep 14, 2012
Messages
9
Any help on this would be much appreciated.

I'd like to change the the color of the bar (meter) in my bar chart using VBA. The actual bar chart is located on "Sheet1" and I'd like to be able to change the color from cell "A3" in "Sheet2".

Please include the following colors as well:
Case "RED": .RGB = vbRed<o:p></o:p>
Case "YELLOW": .RGB =RGB(255, 255, 109)<o:p></o:p>
Case "GREEN": .RGB = RGB(41, 247, 46)<o:p></o:p>
Case "GREY": .RGB = RGB(127, 127, 127)

Here's the coding I'm using that didn't work.


Sub Chart1_Color()<o:p></o:p>
With Sheets("Sheet1").ChartObjects("Chart 1").Fill.Interior.Color<o:p></o:p>
Select Case UCase(Sheets("Sheet2").Range("A3").Value)<o:p></o:p>
Case "RED": .RGB = vbRed<o:p></o:p>
Case "YELLOW": .RGB =RGB(255, 255, 109)<o:p></o:p>
Case "GREEN": .RGB = RGB(41, 247, 46)<o:p></o:p>
Case "GREY": .RGB = RGB(127, 127, 127)<o:p></o:p>
End Select<o:p></o:p>
End With<o:p></o:p>
EndSub

Thanks

 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try something like:
Code:
Sub Chart1_Color()
With Sheets("Sheet 1").ChartObjects(1).Chart.SeriesCollection(1).Format.Fill.ForeColor
    Select Case UCase(Sheets("Sheet 2").Range("A3").Value)
        Case "RED": .RGB = vbRed
        Case "YELLOW": .RGB = RGB(255, 255, 109)
        Case "GREEN": .RGB = RGB(41, 247, 46)
        Case "GREY": .RGB = RGB(127, 127, 127)
    End Select
End With
End Sub
 
Upvote 0
Hi Misca, thanks for responding. I think you're onto something with the code, but it didn't work for me. It changed the chart area (background) itself, but not the actual bar inside the chart. Shouldn't there be something in the code that identifies the chart I'd like to referrence? I know I didn't include it in my original post, but the chart I'd like to change is "Chart 55". Does that matter any?

Thanks again for the help.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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