Hiding a trendline using a button

  • Thread starter Thread starter Phil C
  • Start date Start date
P

Phil C

Hi

I want to hide/unhide a trendline using a button (or maybe 2 buttons, one
for ON and one for OFF?).
What would the code look like?
This is purely a display function, I don't want to remove ('clear') the
trendline.

Thanks

Phil
 
Phil -

You can't really hide the trendline. The option to use no line type is
disabled. And you're stuck with the legend entry. Why not create and
delete the trendline as needed? Attach these two macros to buttons:

Sub TrendlineOn()
ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Trendlines _
.Add Type:=xlLinear, Forward:=0, Backward:=0, _
DisplayEquation:=True, DisplayRSquared:=True
End Sub

Sub TrendlineOff()
ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Trendlines(1) _
.Delete
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top