PDA

View Full Version : Conditional coloring of curves



enfantter
02-22-2008, 02:19 AM
Hi all,
Im trying to write macro that colors curves according to priority.
here is my code:
'1. graf
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
.LineStyle = xlContinuous
End With
'2. graf
ActiveChart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 55
.Weight = xlMedium
.LineStyle = xlContinuous
End With

The problem is that if there is only one curve the macro brakes down.
Therefore, i only want to run the second part (2. graf) if there is a second curve.

I've tried something like this:

if activeChart.seriescollection(2).count > 0
then ...
end if

Bob Phillips
02-22-2008, 03:18 AM
Dim i As Long
Dim aryColours As Variant

aryColours = Array(1, 55, 38, 36) 'etc.

With ActiveChart

For i = 1 To .SeriesCollection.Count

With .SeriesCollection(i)
With .Border
.ColorIndex = aryColours(i)
.Weight = xlMedium
.LineStyle = xlContinuous
End With
End With
Next i
End With

enfantter
03-27-2008, 12:10 AM
I would also like to get rid of the markers ...
I have tried to expand the code with something like this ..
Dim i As Long
Dim aryColours As Variant
aryColours = Array(38, 35, 34, 39, 15, 37, 36, 2, 40) 'etc

With ActiveChart
For i = 1 To .SeriesCollection.Count
With .SeriesCollection(i).Border
.ColorIndex = aryColours(i - 1)
.Weight = xlMedium
.LineStyle = xlContinuous
End With
If ActiveChart.ChartType = xlLineMarkers Then
With .SeriesCollection(i)
.MarkerBackgroundColorIndex = xlAutomatic
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 7
.Shadow = False
End With
End If
Next i
End With

But it is only doing the job for the first series?!

Bob Phillips
03-27-2008, 02:13 AM
Dim i As Long
Dim aryColours As Variant

aryColours = Array(1, 55, 38, 36) 'etc.

With ActiveChart

For i = 1 To .SeriesCollection.Count

With .SeriesCollection(i)
With .Border
.ColorIndex = aryColours(i)
.Weight = xlMedium
.LineStyle = xlContinuous
End With
.MarkerStyle = xlNone
End With
Next i
End With