Add trendlines to all series in a chart with Toggle Button

RaydenUK

Board Regular
Joined
Mar 25, 2014
Messages
74
I am not having any luck with adding toggling trendlines on or off. Ideally, when the toggle is selected, trendlines would be added and once unselected they would disappear. My chart is modified with slicers, which can cause the trendlines to disappear, therefore, the code would have to recognize if trendlines are or aren't present and not throw an error or double up on the lines. I have several series in my chart and would need the trendlines to be formatted the same color as the respective series lines. Any help would be greatly appreciated. Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
best way of avoiding duplication is to delete them all first and then reapply

I use this to produce a polynomial line
Code:
ActiveChart.SeriesCollection(2).Trendlines(1).Select
With Selection.Format.Line
        .Visible = msoTrue
        .Weight = 2
        .ForeColor.ObjectThemeColor = msoThemeColorAccent3
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .BeginArrowheadStyle = msoArrowheadDiamond
        .EndArrowheadStyle = msoArrowheadDiamond
        '.Selection.Forward = 0.5
        '.Backward = 0.5
    End With

    Selection.Type = xlPolynomial
    Selection.Forward = 0.5
    Selection.Backward = 0.5

that was built from recording the action of macro recorder, each one will need to be established as to which line it relates to so a good few lines of code
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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