Chart Coloring With VBA

LionRunner

New Member
Joined
Nov 13, 2014
Messages
19
Hello, I'm creating Winner-Loser charts in VBA using a bar chart with the invert function. Positive bars are to be green, and negative bars red. Below is my portion of the code that is successful in inverting the negative bars to be the left side of the vertical axis while positive bars remain on the rights side. Also, it is successfully changing the positive bars from the default blue color to green; but it does not change the negative bars on the left side of the axis from transparent to red.

Does anyone know how to do that?


ActiveChart.SeriesCollection(1).Select
Selection.InvertIfNegative = True
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With

I even tried to record myself doing it manually but the macro function did not register any new code. I can not figure out how to distinguish the negative bars from the positive bars to use the ForeColor function to change the color.

If anyone needs to test code to answer, the code for red is .ForeColor.RGB = RGB(255, 0, 0)

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Y'all were no help. I figured it out on my own...LOL.

But nah, if anyone comes across this thread in the future and needs to know, the answer is substitute in BackColor like ForeColor, as such:

ActiveChart.SeriesCollection(1).Select
Selection.InvertIfNegative = True
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.BackColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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