+ Reply to Thread
Results 1 to 7 of 7

Consistent Colors for Pivot Charts

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2006
    Posts
    13

    Vba

    Hi!

    That idea seems like it would work. I've only done minimal VBA so I'll check it out. Thank you for providing the "Interior.ColorIndex" hint to get it started.

    If somebody has already done this, can you please post an example?

    Thanks again,
    michael

  2. #2
    Registered User
    Join Date
    06-05-2006
    Posts
    13

    solution

    Hello,

    here is the solution I came up with for this case.

    Private Sub Chart_Calculate()
    Dim i As Integer
    Dim seriesNameValue As String ' holds name of the series within the legend (ex: white, blue, etc)


    'there has to be a better way then this "if". Is it possible to get the name of the series field,
    ' which would be "car color" here?
    'the pivot chart may be manipulated many ways. If we have more than 4, have different field button besides color
    If ActiveChart.Legend.LegendEntries.Count <= 4 Then


    For i = 1 To ActiveChart.Legend.LegendEntries.Count

    seriesNameValue = ActiveChart.SeriesCollection(i).Name

    Select Case seriesNameValue

    Case "Blue"
    ActiveChart.SeriesCollection(i).Interior.ColorIndex = 5
    Case "Red"
    ActiveChart.SeriesCollection(i).Interior.ColorIndex = 3
    Case "Yellow"
    ActiveChart.SeriesCollection(i).Interior.ColorIndex = 6
    Case "White"
    ActiveChart.SeriesCollection(i).Interior.ColorIndex = 2

    Case Else
    'do nothing

    End Select
    Next i
    End If

    End Sub

  3. #3
    Registered User
    Join Date
    01-15-2008
    Posts
    3

    Where does this code go?

    I have no experience with this VBA. Where/how do I put this into my sheet?

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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