Results 1 to 5 of 5

Thread: Clustered Bar Chart

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Clustered Bar Chart

    Hi,
    I am trying to create this chart with dates on x axis and clustered bar chart on y axis showing availability of equipment(Rented,Quoted,Available).

    I tried to write the following macro for the above requirement but i cant get x axis to show the dates and the bar chart on y axis does not show different colours for different status of equipment.

    The data is as follows

    A1:28882 C1:Status
    A2:09/09/2005 C2:Rented
    A3:09/16/2005 C3:Quoted

    The macro is as follows -----------------

    VB Code:
    1. Sub MakeRental()
    2.  
    3. Dim i As Integer
    4.  
    5. Worksheets("Rental").Select
    6. Worksheets("Rental").Range("A2:A3").Select
    7. 'Selection.DateFormat = "mm/dd/yyyy"
    8.            
    9.             Charts.Add
    10.         ActiveChart.Location Where:=xlLocationAsObject, Name:="Rental"
    11.             ActiveChart.ChartType = xlBarClustered
    12.  ActiveChart.SetSourceData Source:=Sheets("Rental").Range("R10"), PlotBy:=xlRows
    13.           ActiveChart.SetSourceData Source:=Sheets("Rental").Range("A1:A3"), PlotBy:=xlRows
    14.        
    15.     With ActiveChart
    16.         .HasLegend = True
    17.         .Legend.Select
    18.         Selection.Position = xlRight
    19.         .SeriesCollection(1).Name = "=""Rented"""
    20.         With ActiveChart.SeriesCollection.NewSeries
    21.             .Name = "Quoted"
    22.             .XValues = ActiveSheet.Range("A2:A3")
    23.         End With
    24.         With ActiveChart.SeriesCollection.NewSeries
    25.             .Name = "Available"
    26.         End With
    27.         .HasDataTable = False
    28.         .HasTitle = True
    29.         .ChartTitle.Characters.Text = "Rental Availability Chart"
    30.     End With
    31.  
    32.         ActiveChart.SeriesCollection(1).Select
    33.         With ActiveChart.ChartGroups(1)
    34.             .Overlap = 100
    35.             .GapWidth = 150
    36.             .HasSeriesLines = False
    37.         End With
    38.      
    39.      For i = 1 To 2
    40.             ActiveChart.SeriesCollection(1).Select
    41.             With Selection.Border
    42.                 .Weight = xlThin
    43.                 .LineStyle = xlAutomatic
    44.             End With
    45.             Selection.Shadow = False
    46.             Selection.InvertIfNegative = False
    47.             With Selection.Interior
    48.             If Worksheets("Rental").Cells(i+1 , 3) = "Rented" Then
    49.                 .ColorIndex = 4 'green
    50.             Else
    51.                 If Worksheets("Rental").Cells(i+1 , 3) = "Quoted" Then
    52.                     .ColorIndex = 3 'red
    53.                 End If
    54.             End If
    55.             .Pattern = xlSolid
    56.             End With
    57.             ActiveChart.ChartGroups(1).SeriesCollection(1).PlotOrder = 1
    58.     Next i
    59.  
    60.         With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory)
    61.            ' .MinimumScale = 9 / 9 / 2005
    62.             '.MaximumScale = 9 / 25 / 2005
    63.         End With
    64. End Sub

    ---------------------------------------------------

    Regards,
    Last edited by RobDog888; Sep 14th, 2005 at 11:34 AM. Reason: Added vbcode tags

Posting Permissions

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



Click Here to Expand Forum to Full Width