VBA/ Macros Conditional formatting Bar graph

Jzfbkr

New Member
Joined
Aug 4, 2014
Messages
29
Im wondering if anyone can help me im looking to make a large number of histograms change colour depending on the bar value.

If the value is below 0 (<0) I need the bar to be green RBG (0,255,0)
if the value is above 0 (>0) i need the bar to change red RBG (255,0,0)

Does anyone have any ideas of how I can achieve this.

Any help will be greatly appreciated.

Regards,

Joe
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Im wondering if anyone can help me im looking to make a large number of histograms change colour depending on the bar value.

If the value is below 0 (<0) I need the bar to be green RBG (0,255,0)
if the value is above 0 (>0) i need the bar to change red RBG (255,0,0)

Does anyone have any ideas of how I can achieve this.

Any help will be greatly appreciated.

Regards,

Joe

What you can do is use your macro recorder to get some of the language set up. Click on one data point and change the color to whatever you want to use then you can add an If statement to get a macro to update the colors of data points.

So, it might look like this

Code:
If Range("A1").Value > Range("B1").Value Then
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(1).Points(5).Select
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Solid
    End With
ElseIf Range("A1").Value < Range("B1").Value Then
     With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent2
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With
End If
 
Upvote 0
Firstly, Thanks for your reply, I'm very new to using macros so I need to make this function as simple as possible. Is there is a simpler way to achieve?

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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