Changing the color of a category in a chart

TamirBasin

New Member
Joined
Apr 11, 2017
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Hello,

After reading the article of Jon Peltier
https://peltiertech.com/vba-conditional-formatting-of-charts-by-category-label/

I an still looking for a way to hardcode within the VBA the colours for the various categories.

Is there a way to do it?

e.g. I have a stacked chart with categories named: 0,1,2,3
I would like to hardcode that category "0" will be filled with red, category "1" will be filled with green...etc.

My scenario:

Working with a pivot chart.
The numbers of columns are changing according to slicer's pick.
I have names of companies on Rows
I have Categories on Columns (this is where my problem is. Not always, all categories appear)


Thank you,
Tamir
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi TamirBasin,
use,,
Code:
Private Sub Chart_Calculate()
On Error Resume Next
With ActiveChart
       .SeriesCollection("0").Interior.ColorIndex = 3     'Red
       .SeriesCollection("3").Interior.ColorIndex = 6                'Yellow
       .SeriesCollection("2").Interior.ColorIndex = 4                'Green
       .SeriesCollection("1").Interior.ColorIndex = 5                 'Blue
End With

End Sub
 
Upvote 0
Hi Pike,

I gave it a quick try and it seems to be doing exactly what I need.

Thank you :)

Regards,
Tamir
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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