Chart slice colours....almost works
Hi Naz,
the first thing that pops into my head is that on a pie chart, isn't each
slice a separate series, not point of series?
If so, then you would want to work with the series, not the point
in your main sub, instead of
ActiveChart.SeriesCollection(1).Points(Slice).Sele ct
use
ActiveChart.SeriesCollection(Slice).Select
And in your sub SliceColour,
SelSlice = Chart.SeriesCollection(1).Points
is going to select the points of the first series every time you call the
sub.
More ideally, you should try defining your sub SelectionFill and SliceColour
with a variable, like (not tested, and again assuming that a pie chart slice
is a series, not a point)
Sub SelectionFill(TargetSeries as Series)
TargetSeries.Fill.OneColorGradient _
Style:=msoGradientDiagonalUp, _
Variant:=2, _
Degree:=0.231372549019608
End sub
and call it with selectionFill
targetseries:=activechart.seriescollection(slice)
By not using select, you'll help your code run faster (and I always get into
trouble when I use .select)
Do the same with your SliceColour.
HTH
Mike.
"Naz" wrote in message
...
Hi,
I want to create a little macro that automatically changes the colours of
each slice in a chart to a pre-defined colour. I can't create a
pre-defined
user chart for various network reasons. So far I have the following long
winded, but easy for me to understand code, but the case select module
where
the colours are selected doesn't work, i've only had a rough guess as to
how
it should work, and if you can do a case select for chart slices, so i may
be
well out.
Sub ChartColours()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
Slice = 1
On Error Resume Next
For x = 1 To 20 ' Im going to assume no more than 20 slices
ActiveChart.SeriesCollection(1).Points(Slice).Sele ct
Module1.SelectionFill
Module1.SliceColour
Slice = Slice + 1
Next x
End Sub
Private Sub SelectionFill()
Selection.Fill.OneColorGradient Style:=msoGradientDiagonalUp,
Variant:=2, _
Degree:=0.231372549019608
End Sub
Private Sub SliceColour()
SelSlice = Chart.SeriesCollection(1).Points <<< I'm stuck at
this point
Select Case SelSlice
Case 1
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 1
End With
Case 2
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 2
End With
Case 3
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 3
End With
Case 4
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 4
End With
Case 5
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 5
End With
End Select
End Sub
Any help to get it working would be greatly appreciated, help to make it
work and more efficient would be even more appreciated !
regards
--
_______________________
Naz,
London
|