Hiding a trendline using a button

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
 
J

Jon Peltier

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/
_______
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top