PC Review


Reply
Thread Tools Rate Thread

Edit Chart Macro Help - Skip ActiveChart Selection if no data

 
 
conorfinnegan@gmail.com
Guest
Posts: n/a
 
      6th Apr 2007
I have a macro that I have recorded. I know there is some duplicate
information here, but I am not worried about that. I have included a
part of the code below. Basically if the "SeriesCollection" is not
available on the chart for which I run the macro, the macro fails and
gives me a runtime error. So in the example below, if
SeriesCollection(3) doesn't have data, I would like it to jump to
SeriesCollection(4). Is there a way to do that? Can anyone please
help?

I would greatly appreciate it.

Conor

ActiveChart.SeriesCollection(3).Select
With Selection.Border
.ColorIndex = 10
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
ActiveChart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 10
.Weight = xlMedium
.LineStyle = xlDash
End With

 
Reply With Quote
 
 
 
 
Tyla
Guest
Posts: n/a
 
      6th Apr 2007
Conor,

No seeing the whole macro limits this response but a general
approach you might want to take is below. It makes huge assumptions by
hardiwring all sorts of things so it's probably not something yuo want
in production code, but it does show a use of "On Error" which may
help here. The key feature here is isolating the formatting of the
particular series into separate macros, and use the "On error goto
byebye" line within each pimpSeries() macro to bail out gracefully if
there's a problem, e.g. no applicable data series.
Again, it isn't elegant or producton-level code, but it may give you
hints on a useful direction.
HTH

/ Tyla /

Option Explicit


Sub pimpMyChart()

'..whatever..
Call pimpSeries3
Call pimpSeries4
' etc.

End Sub

Sub pimpSeries3()
On Error GoTo byebye:
ActiveChart.SeriesCollection(3).Select
With Selection.Border
.ColorIndex = 10
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With

byebye:
End Sub

Sub pimpSeries4()
On Error GoTo byebye:
ActiveChart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 10
.Weight = xlMedium
.LineStyle = xlDash
End With
byebye:
End Sub




On Apr 6, 1:43 pm, conorfinne...@gmail.com wrote:
> I have a macro that I have recorded. I know there is some duplicate
> information here, but I am not worried about that. I have included a
> part of the code below. Basically if the "SeriesCollection" is not
> available on the chart for which I run the macro, the macro fails and
> gives me a runtime error. So in the example below, if
> SeriesCollection(3) doesn't have data, I would like it to jump to
> SeriesCollection(4). Is there a way to do that? Can anyone please
> help?
>
> I would greatly appreciate it.
>
> Conor
>
> ActiveChart.SeriesCollection(3).Select
> With Selection.Border
> .ColorIndex = 10
> .Weight = xlMedium
> .LineStyle = xlContinuous
> End With
> With Selection
> .MarkerBackgroundColorIndex = xlNone
> .MarkerForegroundColorIndex = xlNone
> .MarkerStyle = xlNone
> .Smooth = False
> .MarkerSize = 3
> .Shadow = False
> End With
> ActiveChart.SeriesCollection(4).Select
> With Selection.Border
> .ColorIndex = 10
> .Weight = xlMedium
> .LineStyle = xlDash
> End With



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ActiveChart, Data!R code JP Microsoft Excel Programming 0 29th Jul 2008 07:10 PM
using a macro to edit the data range of a chart Monkey-See, Monkey-Do Microsoft Excel Programming 2 29th Jun 2008 05:12 PM
Data selection on line chart Qiset Microsoft Excel Charting 2 11th Aug 2005 02:08 PM
Excel VBA macro - need to edit code to skip a year adun3434 Microsoft Excel Programming 0 1st Apr 2004 09:14 PM
Argument List Of ActiveChart.Location And ActiveChart.ChartType Mo Microsoft Excel Programming 2 1st Sep 2003 11:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:30 PM.