VBA code for fill color and transparency in a 3 series line chart with only one series as an area series

travellerva

New Member
Joined
Mar 31, 2012
Messages
47
Office Version
  1. 365
Platform
  1. MacOS
I have VBA code for creating a line chart with 3 Series - 2 of which are lines and the third is an area line with fill below the line to the axes. Although (I think) I specify the RGB color for the fill area, it always comes out grey. Any changes to my RGB codes have no effect. Can someone help me correct my VBA code so I can define the color and transparency of the fill area. The following is the code I'm using now (subroutines called are just to create each SeriesCollection).

VBA Code:
 Sheets("Chart").ChartObjects("Chart Portfolio").Activate
    
    Call AddNewSeries("SJM Benchmark", BenchmarkValues, DateRange, 1.5)  '(last parameter is line width)
        ActiveChart.SeriesCollection(1).Select
        With Selection.Format.Line
            .Visible = msoTrue
            .ForeColor.RGB = RGB(0, 128, 0)
        End With
    
     Call AddNewSeries("SPY", SPYValues, DateRange, 1.5)
        ActiveChart.SeriesCollection(2).Select
        With Selection.Format.Line
            .Visible = msoTrue
            .DashStyle = msoLineDash
            .ForeColor.ObjectThemeColor = msoThemeColorText1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0
        End With
        
        Call AddNewSeries("SJM Portfolio", SJMPortfolioValues, DateRange, 1.8)
        ActiveChart.SeriesCollection(3).Select
            With Selection.Format.Line
                .Visible = msoTrue
                .ForeColor.RGB = RGB(255, 0, 0)
            End With
            With Selection
                .Format.Fill.ForeColor.RGB = RGB(0, 128, 0)
            End With

I only want the 3rd line to have area fill. I note that that line must be the last one specified, else any subsequent line is also filled, but I can live with that.

Many thanks.
 

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

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

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