Consulting

Results 1 to 3 of 3

Thread: VBA for multi-colored pivot chart bars?

  1. #1
    VBAX Regular
    Joined
    Nov 2012
    Posts
    57
    Location

    VBA for multi-colored pivot chart bars?

    Hello

    Trying to create a pivot chart (bar chart) from a pivot table. Excel doesnt seem to want to let me have multiple colored bars. Is there a way to do this in VBA during the creation of the chart? Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If it ius all one data series then it would be the same colour. You can change the points like so

        With ActiveChart.SeriesCollection(1)
            With .Points(1).Format.Fill
                .ForeColor.ObjectThemeColor = msoThemeColorAccent1
                .ForeColor.TintAndShade = 0
                .ForeColor.Brightness = 0
                .Solid
            End With
            With .Points(2).Format.Fill
                .Visible = msoTrue
                .ForeColor.ObjectThemeColor = msoThemeColorText2
                .ForeColor.TintAndShade = 0
                .ForeColor.Brightness = 0.8000000119
                .Transparency = 0
                .Solid
            End With
            With .Points(3).Format.Fill
                .Visible = msoTrue
                .ForeColor.ObjectThemeColor = msoThemeColorText2
                .ForeColor.TintAndShade = 0
                .ForeColor.Brightness = 0.8000000119
                .Solid
            End With
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    If you only have 1 series in the pivot chart then you should be able to format the series fill and enable "Vary color by points".

    If you must use code then
    Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    
        ActiveSheet.ChartObjects(1).Chart.ChartGroups(1).VaryByCategories = True
        
    End Sub
    Cheers
    Andy

Posting Permissions

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