Solved

Change the color of a ChartSeries to correspond to Grouping

Posted on 2011-03-15
2
219 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
ID: 35137291
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
 
LVL 1

Author Comment

by:cErasmus
ID: 35137462
Thank you very much
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 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