+ Reply to Thread
Results 1 to 6 of 6

Change series colour for all charts on a worksheet.

Hybrid View

DonaldDump Change series colour for all... 08-27-2013, 07:38 PM
ajryan88 Re: Change series colour for... 08-27-2013, 09:47 PM
DonaldDump Re: Change series colour for... 08-28-2013, 05:14 PM
ajryan88 Re: Change series colour for... 08-28-2013, 05:44 PM
DonaldDump Re: Change series colour for... 08-28-2013, 05:54 PM
ajryan88 Re: Change series colour for... 08-28-2013, 06:12 PM
  1. #1
    Registered User
    Join Date
    08-27-2013
    Location
    Manhattan, US
    MS-Off Ver
    Excel 2013
    Posts
    3

    Change series colour for all charts on a worksheet.

    Hello. This is my first post on this forum. ...I'll be much obliged by any help offered to this problem! I have a worksheet where I need to set all of the colours of my charts back to a default palette. I was exploring two options:

    Sub ColourChart()
    Dim oChart As ChartObject
    For Each oChart In ActiveSheet.ChartObjects
    With oChart
    .SeriesCollection(1).Interior.Color = RGB(0, 77, 154)
    .SeriesCollection(2).Interior.Color = RGB(191, 191, 191)
    .SeriesCollection(3).Interior.Color = RGB(127, 127, 127)
    .SeriesCollection(4).Interior.Color = RGB(74, 140, 213)
    .SeriesCollection(5).Interior.Color = RGB(100, 100, 100)
    End With
    Next oChart
    As some charts have fewer than 5 series, I thought it best to use something like the following:

    Sub ColourChart()
    Dim i As Integer
    Dim oChart As ChartObject
    
    For Each oChart In ActiveSheet.ChartObjects
    For i = 1 To oChart.SeriesCollection.Count(i)
    With oChart.SeriesCollection(i)
       Select Case i
          Case "1": .Interior.Color = RGB(0, 77, 154)
          Case "2": .Interior.Color = RGB(191, 191, 191)
          Case "3": .Interior.Color = RGB(127, 127, 127)
          Case "4": .Interior.Color = RGB(74, 140, 213)
          Case "5": .Interior.Color = RGB(100, 100, 100)
        End Select
    End With
    Next i
    Next oChart
    End Sub
    However, both return errors of the type: "Object doesn't support this property or method", highlighting the first line after the "With" statement... though I suspect there may be errors beyond just that...

    I'm using Excel 2013. The series on the different charts are not named 1-5, but there are usually 5 of them.

    Again - many thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Change series colour for all charts on a worksheet.

    Hi,

    Try changing
    For i = 1 To oChart.SeriesCollection.Count(i)
    to
    For i = 1 To oChart.SeriesCollection.Count
    You shouldn't need to reference "i" to return the count of SeriesCollection.

    If this doesn't help, can you please upload a workbook so that I may debug your code in context?

    Hope this helps

  3. #3
    Registered User
    Join Date
    08-27-2013
    Location
    Manhattan, US
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Change series colour for all charts on a worksheet.

    Hi Ajryan88. Thank you for your reply. It has not resolved the issue for me - same error. Sadly I cannot upload the actual workbook as it is too large, but I have uploaded a workbook with the same sort of construction. Note that the function gets called on the "worksheet activate" event.

    http://temp-share.com/download/4593a...371ac96d0df518 (Ensure to click the grey {not green} 'Download' button.)

    (I have not used this filesharer before.)
    Last edited by DonaldDump; 08-28-2013 at 05:16 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Change series colour for all charts on a worksheet.

    Hi,

    Try this code:
    Sub ColourCharts()
        Dim i As Integer
        Dim oChart As ChartObject
        
        For Each oChart In ActiveSheet.ChartObjects
            For i = 1 To oChart.Chart.SeriesCollection.Count
                With oChart.Chart.SeriesCollection(i)
                    Select Case i
                        Case "1": .Interior.Color = RGB(0, 77, 154)
                        Case "2": .Interior.Color = RGB(191, 191, 191)
                        Case "3": .Interior.Color = RGB(127, 127, 127)
                        Case "4": .Interior.Color = RGB(74, 140, 213)
                        Case "5": .Interior.Color = RGB(100, 100, 100)
                    End Select
                End With
            Next i
        Next oChart
    End Sub
    The problem was that a "ChartObject" (oChart) doesn't have a "SeriesCollection" attached to it, but it does have a "Chart" element which does have a series collection. So as you can see, the adjustments are very minor, and you were very close.

    Hope this helps

  5. #5
    Registered User
    Join Date
    08-27-2013
    Location
    Manhattan, US
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Change series colour for all charts on a worksheet.

    Excellent. This works perfectly - you guys do a great service on forums like these, thank you.

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Change series colour for all charts on a worksheet.

    You're welcome!

    Please don't forget to mark this thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro with IF statement for if a series exists change colour of line in graph
    By sim410 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-21-2012, 06:20 AM
  2. Need help getting column charts to change colour based on values
    By NPC1977 in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 10-08-2012, 07:44 PM
  3. Change colour of chart series
    By downunderthunder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-06-2010, 09:20 PM
  4. Stacked Area Chart Series Colour Change
    By downunderthunder in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2010, 09:18 PM
  5. Change lots of series on a scatter graph to one colour
    By rmellison in forum Excel General
    Replies: 0
    Last Post: 02-03-2006, 07:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1