Auto change chart column colors

jmattioli

New Member
Joined
Jul 27, 2011
Messages
5
Hey all, I am stumped with this, and I haven't used VBA at all. I have 2 columns of data that are charted in a 3D clustered column chart, which I have made "dynamic" to only chart the most recent 12 records. My question is, is there a way to automatically change the color of the columns in the chart based on the data i have recorded? Specifically, if there has been two consecutive increases, the column needs to change to red.

Example:
Date: ValA ValB
1/1 5 4
2/1 7 3
3/1 8 3
4/1 2 6
5/1 5 7

The data point in ValA for 3/1 would automatically change to red because it has increased two times in a row. Likewise, the data point in ValB for 5/1 would also be red, because of increasing two times in a row.

Any ideas? Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This can be done with or without macros.
Without macros will involve adding series to the charts which overlie existing series. You would set up extra columns for these series. An example for column B values in column F (F4 formula is copied down):
Excel Workbook
ABCDEF
1>14>30Len>14 rising
201-Apr973212#N/A
308-Apr7737#N/A
415-Apr1215#N/A
522-Apr1112#N/A
629-Apr1411#N/A
706-May15715
813-May115#N/A
920-May1611#N/A
1027-May158#N/A
1103-Jun1711#N/A
1210-Jun221622
1317-Jun2114#N/A
1424-Jun3113#N/A
1501-Jul2912#N/A
Sheet

I chose #N/A to appear in cells because excel doesn't attempt to chart them. But because you've used clustered charts it gets very fiddly to have the bars overlie each other (I haven't tried very hard).
John Peltier explores this technique here: http://peltiertech.com/Excel/Charts/ConditionalChart1.html and there's a video here.

I think using VBA (macros) might be better, in the file I've posted here at box.net, I've written a small macro (adapted from something I found on the interweb and possibly ascribable to Andy Pope, since he's pretty good on this sort of stuff - see his pages here) which runs through all the charts on the active sheet (there's only one at the moment) and changes the fill colour for the first series bars (only the first series at the moment) to red if a bar is the 3rd in a series of 3 rising bars. This macro runs on the press of the added button on that sheet. So experiment by changing the values in column B and pressing the button (macros will need to have been enabled).

You/we still need to develop this as I'm sure you'll want to do this on multiple series within (probably) multiple charts, even on multiple sheets.

You might want to change how you highlight the bars, making multiple series red may make it difficult to identify just which series a given highlighted bar is a member of. Perhaps change the transparency, or the border thickness or colour, or…

Of course, later you'll be able to dispense with the button and have the macro triggered automatically.

Is this vba solution one you'd be happy to proceed with?
 
Last edited:
Upvote 0
This can be done with or without macros.
Without macros will involve adding series to the charts which overlie existing series. You would set up extra columns for these series. An example for column B values in column F (F4 formula is copied down):
Excel Workbook
ABCDEF
1>14>30Len>14 rising
201-Apr973212#N/A
308-Apr7737#N/A
415-Apr1215#N/A
522-Apr1112#N/A
629-Apr1411#N/A
706-May15715
813-May115#N/A
920-May1611#N/A
1027-May158#N/A
1103-Jun1711#N/A
1210-Jun221622
1317-Jun2114#N/A
1424-Jun3113#N/A
1501-Jul2912#N/A
Sheet

I chose #N/A to appear in cells because excel doesn't attempt to chart them. But because you've used clustered charts it gets very fiddly to have the bars overlie each other (I haven't tried very hard).
John Peltier explores this technique here: http://peltiertech.com/Excel/Charts/ConditionalChart1.html and there's a video here.

I think using VBA (macros) might be better, in the file I've posted here at box.net, I've written a small macro (adapted from something I found on the interweb and possibly ascribable to Andy Pope, since he's pretty good on this sort of stuff - see his pages here) which runs through all the charts on the active sheet (there's only one at the moment) and changes the fill colour for the first series bars (only the first series at the moment) to red if a bar is the 3rd in a series of 3 rising bars. This macro runs on the press of the added button on that sheet. So experiment by changing the values in column B and pressing the button (macros will need to have been enabled).

You/we still need to develop this as I'm sure you'll want to do this on multiple series within (probably) multiple charts, even on multiple sheets.

You might want to change how you highlight the bars, making multiple series red may make it difficult to identify just which series a given highlighted bar is a member of. Perhaps change the transparency, or the border thickness or colour, or…

Of course, later you'll be able to dispense with the button and have the macro triggered automatically.

Is this vba solution one you'd be happy to proceed with?


Thanks. I am going to try and play around with this today. In the meantime, do you know how to make the width of the columns wider instead of having the series being so close to each other?
 
Upvote 0
do you know how to make the width of the columns wider instead of having the series being so close to each other?
I'd guess this is because the x-axis is a date and there is room left for 6 days between plotted data. Try changing the x-axis format to type Text.
 
Upvote 0
I'd guess this is because the x-axis is a date and there is room left for 6 days between plotted data. Try changing the x-axis format to type Text.

That worked! Man, thanks a lot for all your help. I'll let you know how the macros work out and I will probably have questions when I try to add the other column to it in order to have the macro auto format each data series that has 2 consecutive increases.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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