0

I have two charts on the same sheet, one pie, one column. They show the same titles, from the same rows but data from different columns. (there may be up to 100 data series or slices) in the charts.

I need to make them use the same colours for the same titles, but Excel assigns different colours. How can I sort that?

FYI the data for the charts is filtered fairly regularly so the titles do change, but both charts always contain the same titles.

Thanks

M

M. H
  • 199
  • 3
  • 5
  • 13

1 Answers1

0

Following VBA code is doing the formatting:

Option Explicit

Sub sameColors()

Dim ColChart As Chart
Dim PieChart As Chart
Dim NumberOfTitles As Integer
Dim actTitle As Integer
Dim ColorColumn As Long

Set ColChart = ActiveSheet.ChartObjects(1).Chart
Set PieChart = ActiveSheet.ChartObjects(2).Chart
NumberOfTitles = ColChart.SeriesCollection.Count
For actTitle = 1 To NumberOfTitles
    ColorColumn = ColChart.SeriesCollection(actTitle).Interior.Color
    PieChart.SeriesCollection(1).Points(actTitle).Interior.Color = ColorColumn
Next actTitle

End Sub

This is assuming that Chartobjects(1) is your Columnchart and Chartobjects(2) is your PieChart.

You'll get an Error if this is not the case.

The Colors in the Piechart will be set to the colors which are in the Columnchart

You have to run the code after each filtering of the data table

Axel Stache
  • 159
  • 5