changing colours on chart series

J

JillC

I am using macros to create 4 charts from the data on one spreadsheet, each
chart (consisting of 2 series) has different colours. Using the coding below
will change the colours after running the macro. When the macro finishes,
Series 2 on each chart is selected. When I click away from the chart the
colour reverts back to the original default colours. Annoyingly it sometimes
does not happen to all four charts, but 3 out of the 4 will be wrong.
I know there is a glitch with pivot table charts, and although the data
originally came from a pivot table, the data I am using has been copied and
pasted as values. Do I need to use the pivot table solution to get my coding
to work properly or is there something wrong with the coding?

Sub ColourReset()
' reset colours of charts
mySheet1 = "Chart1"
myColour1 = 46
myColour2 = 40
ColourCharts
mySheet1 = "Chart2"
myColour1 = 10
myColour2 = 35
ColourCharts
mySheet1 = "Chart3"
myColour1 = 54
myColour2 = 39
ColourCharts
mySheet1 = "Chart4"
myColour1 = 11
myColour2 = 37
ColourCharts

End Sub

Sub ColourCharts()

'
Sheets(mySheet1).Activate
ActiveSheet.ChartObjects(1).Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
Selection.InvertIfNegative = False
With Selection.Interior
.ColorIndex = myColour1
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
Selection.InvertIfNegative = False
With Selection.Interior
.ColorIndex = myColour2
.Pattern = xlSolid
End With
End Sub
 

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