Solved

Change the color of a ChartSeries to correspond to Grouping

Posted on 2011-03-15
2
218 Views
Last Modified: 2012-05-11
Hi All
I’m using excel 2010. What I have is a workbook with 3 sheets; Summary, RFQEvaluation and OpenPRsAge. The data is contained in RFQEvaluation, Summary has a pivot chart linked to a pivot table in OpenPRsAge. I have written some code that will group the Age in OpenPRsAge by 10 starting at 0 and ending at 50 so there will be 6 chart series. I have also coded that the color of series 1 will be green, series 2 light green, series 3 yellow, series 4 orange, series 5 red and series 6 black. If there is data for each series it works fine. The problem I’m having is that if there is no data for 0-9 then 10-19 will be series 1 and will be green. What I need is for 0-9 to be green, 10-19 light green and so on. So in other words if there is data in 0-9 and NO data in 10-19 and again in 20-29 I need to have 20-29 to be orange and not light green. I have added a workbook.  If all the 2’s are changed to 10 0-9 falls away and the colors are not allocated correctly
Thanks in advance
Elmo
 UploadToExpertsPivotColors.xlsm UploadToExpertsPivotColors.xlsm
0
Comment
Question by:cErasmus
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
Comment Utility
Try changing the code to:
Sub ChartseriesColor()

Dim AgeRange As Range


Application.EnableEvents = False
Application.ScreenUpdating = False


'**To make sure OpenPRsAge is grouped right
With Sheets("OpenPRsAge")
   .PivotTables("PivotTable1").PivotCache.Refresh

   Set AgeRange = .Cells.Find("Age")
   AgeRange.Group Start:=0, End:=50, By:=10
   With .PivotTables("PivotTable1").PivotFields("Age")
      .ShowAllItems = True
      .PivotItems("<0").Visible = False
   End With
End With
'**


'**
Dim Counter
'On Error GoTo myError
Counter = 0
Do Until Counter = 6
    Counter = Counter + 1
    
    
    With Sheets("Summary").ChartObjects("Chart 2").Chart.SeriesCollection(Counter).Format.Fill
        
        If Counter = 1 Then
            'green
            .ForeColor.RGB = RGB(0, 176, 80)
        ElseIf Counter = 2 Then
            'light green
            .ForeColor.RGB = RGB(146, 208, 80)
        ElseIf Counter = 3 Then
            'yellow
            .ForeColor.RGB = RGB(255, 255, 0)
        ElseIf Counter = 4 Then
            'orange
            .ForeColor.RGB = RGB(255, 192, 0)
        ElseIf Counter = 5 Then
            'red
            .ForeColor.RGB = RGB(255, 0, 0)
        ElseIf Counter = 6 Then
            'black
            .ForeColor.ObjectThemeColor = msoThemeColorText1
        
        End If

    End With

Loop



Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


Exit Sub

myError:
If Err.Description = "Invalid Parameter" Then
    Resume Next
Else
MsgBox Err.Description
End If

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Open in new window

0
 

Author Comment

by:cErasmus
Comment Utility
Thank you very much
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now