Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Charting / July 2004

Tip: Looking for answers? Try searching our database.

Trap error for trendline clear button?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil C - 29 Jul 2004 16:56 GMT
Hi everyone

I have 2 data series on an XY scattergraph. I have created buttons for
turning the associated trendlines ON/OFF.
Trendline 1 is the trendline for series 1.
The sheet opens with trendline 1 on and trendline 2 off
One button (A) turns trendline 1 off and trendline 2 on
The other button (B) does the opposite (turns trendline 2 off and trendline
1 on)
The idea is that one trendline replaces the other.
However, if the user clicks the 'wrong button' (e.g clicks A when trendline
1 is already off) I get a runtime error 1004 (unable to get the trendline
properties of the series class). Fair enough.
What is the simplest way to trap this error?

Existing code attached to one of the buttons ('1 off, 2 on')

ActiveSheet.ChartObjects("Chart 7").Activate
   ActiveChart.SeriesCollection(1).Trendlines(1).Select
   Selection.Delete
   ActiveChart.SeriesCollection(2).Select
   ActiveChart.SeriesCollection(2).Trendlines.Add(Type:=xlLinear,
Forward:=0, _
       Backward:=0, DisplayEquation:=False, DisplayRSquared:=False).Select

Thanks for your help.

Phil
Andy Pope - 29 Jul 2004 17:22 GMT
Hi Phil,

Could you make use of the Trendlines.Count property?

If ActiveChart.SeriesCollection(1).Trendlines.Count = 1 Then
ActiveChart.SeriesCollection(1).Trendlines(1).Delete

Cheers
Andy

> Hi everyone
>
[quoted text clipped - 24 lines]
>
> Phil

Signature

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.