excelexcel-2010excel-charts

Restore chart default colours after deleting series


Hi I can't believe I can't find an answer to this but I have looked.

In Excel I want to restore the default colour palette order to a chart that I have deleted some series from.

Ie if my colour palette goes: red, green, blue, yellow, orange, grey and I originally have a chart with 6 lines they are in this order. Start with this graph

If I then delete the green, blue and yellow lines:

Deleted some series

I am hoping there is a way to update the chart so instead of the remaining red, orange, grey I can return it to red, green, blue - Ie what I would get if I recreated the final chart from scratch: Want to end up with this

Obviously I could recreate from scratch or manually change colours but I do this fairly frequently and its often a lot easy to select all columns and delete the ones I don't want than to go through and make a chart line by line.

I'm using corporate excel with minimal permissions so no addins please. Just want to know if this is possible in standard excel environment.


Solution

  • I did some testing, most macros that just adjust the colors seem to create a mess, especially if you want to adjust the chart by using the "chart design->change colours" option. So I went for "remove all series and add them again" approach. This works fine on my PC (Office 365). Select the chart and run this macro (you can assign a shortcut key to make this faster: https://www.excelcampus.com/vba/keyboard-shortcut-run-macro/ ):

    Sub ChartRemoveReAddData()
    
        Dim DataArr() As String
        Dim n As Long
        
        Set AChart = Application.ActiveChart
        If Not AChart Is Nothing Then
            'First add series to DataArr
            i = 0
            For Each Ser1 In AChart.SeriesCollection
                sFmla = Ser1.Formula
                ReDim Preserve DataArr(i)
                DataArr(i) = sFmla
                i = i + 1
            Next Ser1
            'Again, but now reverse to remove them
            For n = AChart.SeriesCollection.Count To 1 Step -1
                AChart.SeriesCollection(n).Delete
            Next n
            AChart.ClearToMatchStyle
            AChart.ClearToMatchColorStyle
            For i = 0 To UBound(DataArr)
                Set S = AChart.SeriesCollection.NewSeries
                S.Formula = DataArr(i)
            Next i
        End If
       
    End Sub
    

    And a bit more detail to the colouring: Excel has 10 theme colours (plus 2 for hyperlinks) that you can find if you click e.g. the font colour or background colour button. The last 6 of that overview are the relevant ones for charts. The are named Accent 1 to Accent 6 (https://learn.microsoft.com/en-us/office/vba/api/Office.MsoThemeColorIndex). And as you can see those colours are showing up when you select your chart and select "chart design - change colours". So e.g. ChartColor = 11 (in VBA) means that your chart shows the colours Accent 1 (first series), Accent 3 (second series), Accent 5 (3rd series).

    Excel Theme colour example