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
42
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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