+ Reply to Thread
Results 1 to 2 of 2

A color for each of the bar

Hybrid View

gamaz A color for each of the bar 10-05-2009, 12:32 PM
Andy Pope Re: A color for each of the... 10-06-2009, 05:38 AM
  1. #1
    Registered User
    Join Date
    07-15-2009
    Location
    Rockford, IL
    MS-Off Ver
    Excel 2003
    Posts
    38

    A color for each of the bar

    Hi,
    I am recording a macro to generate a excel graph from a table as show below. Everything works fine. I need to use this code for automation purpose.

    However the bar graph generated has only one color which is the default color blue. Is there any way for each of the four bars I can assign a color for each type of category

    eg Total Green color, C/C Blue, CAR Yello and SCAR Gray.
    I appreciate any help for resolution of this issue. Thanks
     
    Sub Macro1()
    '
    ' Macro1 Macro
    
    '
    
    '
        Range("A1:B5").Select
        Charts.Add
        ActiveChart.ChartType = xl3DColumnClustered
        ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B5"), PlotBy:= _
            xlColumns
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "Car Details"
            .Axes(xlCategory).HasTitle = False
            .Axes(xlSeries).HasTitle = False
            .Axes(xlValue).HasTitle = False
        End With
        ActiveWindow.Visible = False
        Windows("Book1").Activate
        Range("O30").Select
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.SeriesCollection(1).Select
        ActiveChart.Walls.Select
        ActiveChart.ChartArea.Select
        ActiveWindow.Visible = False
        Windows("Book1").Activate
        Range("N32").Select
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.ChartArea.Select
        ActiveChart.ApplyDataLabels AutoText:=True, LegendKey:=False, _
            HasLeaderLines:=False, ShowSeriesName:=False, ShowCategoryName:=False, _
            ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False
        ActiveChart.HasDataTable = True
        ActiveChart.DataTable.ShowLegendKey = True
        ActiveWindow.SelectedSheets.PrintPreview
        ActiveChart.SeriesCollection(1).Select
    End Sub
    CategoryCount
    Total 44
    C/C 17
    CAR 12
    SCAR 15

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: A color for each of the bar

        ActiveChart.ChartGroups(1).VaryByCategories = True
    Cheers
    Andy
    www.andypope.info

+ 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