Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change the color of a ChartSeries to correspond to Grouping

Posted on 2011-03-15
2
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

597 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