+ Reply to Thread
Results 1 to 2 of 2

Gant Chart

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    287

    Gant Chart

    Ok, guys i am looking for some help regarding Gant Charts. I have managed to create something similar to what i am working for using an example from Lacher and Gant Charts. i am now stuck as I can enter more than 40 status as it then gives me an error. The following is the code: Can any1 highlight where i need to make any changes to stop the error from occuring:

    Option Explicit
    
    Sub CreateTimeChartData()
    
        Dim vTimeData As Variant
        Dim i As Integer
        Dim sRoom As String
        Dim vLastEndTime As Variant
        Dim oSeries As Series
        '\ set up
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        '\ create chart data worksheet
        With Worksheets("TimeData").Range("TimeList").CurrentRegion
            .Sort Key1:="Room", Key2:="Start Time", Header:=xlYes
            vTimeData = .Value
            Worksheets.Add
            On Error Resume Next
                Worksheets("ChartData").Delete
                Charts("TimeChart").Delete
            On Error GoTo 0
            ActiveSheet.Name = "ChartData"
            .Columns(1).AdvancedFilter Action:=xlFilterCopy, _
                CopyToRange:=Range("A1"), Unique:=True
        End With
        Range("a1").Select
        For i = 2 To UBound(vTimeData)
            If vTimeData(i, 1) <> Selection.EntireRow.Cells(1) Then
                Selection.Offset(1).EntireRow.Cells(1).Select
                Selection.Value = vTimeData(i, 1)
                vLastEndTime = 0
            End If
            Selection.Offset(0, 1).Select
            Selection.Value = vTimeData(i, 2) - vLastEndTime
            Selection.Offset(0, 1).Select
            Selection.Value = vTimeData(i, 3) - vTimeData(i, 2)
            vLastEndTime = vTimeData(i, 3)
        Next i
        With Selection.CurrentRegion
            .Offset(0, 1).NumberFormat = "h:mm AM/PM"
            .Columns(2).Cells(1) = "Start Time"
            For i = 3 To .Columns.Count
                If i Mod 2 <> 0 Then
                    .Columns(i).Cells(1) = "Used"
                Else
                    .Columns(i).Cells(1) = "Not Used"
                End If
            Next i
        End With
        Charts.Add
        ActiveChart.Name = "TimeChart"
        ActiveChart.ChartWizard Source:=Sheets("ChartData").Range("A1").CurrentRegion, _
            Gallery:=xlBar, format:=3, PlotBy:=xlColumns, CategoryLabels _
            :=1, SeriesLabels:=1, HasLegend:=2
    
        For Each oSeries In ActiveChart.SeriesCollection
            If oSeries.PlotOrder Mod 2 <> 0 Then
                oSeries.Border.LineStyle = xlNone
                oSeries.Interior.ColorIndex = xlNone
            Else
                oSeries.Interior.ColorIndex = 5
            End If
        Next oSeries
        
       With ActiveChart.Axes(xlValue)
            .MajorUnit = 0.0416666666
            .TickLabels.NumberFormat = "h AM/PM"
            .HasMajorGridlines = True
       End With
       
        With ActiveChart.Axes(xlCategory)
           .ReversePlotOrder = True
        End With
        
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "AGENT STATUS REPORT"
        End With
    End Sub
    Thanks in advance. I have also attached a sample workbook..
    Attached Files Attached Files
    Last edited by aftabn10; 06-16-2008 at 10:33 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,448
    I used your file to create 47 items.
    What exactly do you get an error doing?
    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