VBA Chart Series Color - Complex Formatting Prompt Prevents User Defined Color

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
Greetings all.

I've been working with a chart in VBA, and I have been getting some inconsistent results when applying a color to one of the series. The code is correct, and VBA executes it- however it is not applied.

If I try to color the series manually, I then get the following excel prompt:
Code:
Complex formatting that is applied to the selected chart may take a while to display. Do you want to continue using the formatting?

Of course, if I click OK, it colors the series instantaneously. I believe this is preventing me from coloring the series, although I do not receive the prompt while the code is running. I do turn everything off, then back on upon completion however.


So my question is- am I correct in assuming this is the root cause? If so, what are the possible workarounds? Has anyone else had an issue like this?

It uses this default code to apply the color:

Code:
 With Sheets("Sheet 1").ChartObjects("myChart").Chart.FullSeriesCollection(1) 
            .MarkerStyle = -4142 'No markers
            .Format.Line.Visible = msoTrue
            .Format.Line.ForeColor.RGB = RGB(51, 204, 51)
            .Format.Line.Transparency = 0
            .Format.Line.Weight = 1.75
            .Format.Line.DashStyle = msoLineDash
        End With

It also seems that no code beyond the point of foreColor.RGB is applied as well (only within the WITH statement), since the dash style is not applied either.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
So one workaround I'm using is to create the series as a place holder, and set the color but with a visible property of False by default. Then only push values to it (reference x, y) and set visible to True if I need it. This is opposed to creating and setting color on the fly when the "new" series is necessary.
 
Upvote 0

Forum statistics

Threads
1,215,888
Messages
6,127,590
Members
449,386
Latest member
owais87

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