Creer un gantt chart a partir d'excel

Contenu du snippet

Pour creer un Gantt Chart a partir d'un tableau excel de la forme:

;Start Date; progress; Due Date
phase 1; 01/01/2004; 150; 360;
phase 2; 01/01/2005; 150; 360;
phase 3; 01/01/2006; 150; 360;

progress et due date sont en nombre de jours

en argument: les donnees sources (ex: Sheets("mySheet").Range("A1:D10"))

Source / Exemple :


Sub createGanttChartType(data As Range)
   
    Charts.Add
    ActiveChart.ChartType = xlBarStacked
    ActiveChart.SetSourceData Source:=data, PlotBy:=xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:="GanttChartData"
    ActiveChart.PlotArea.Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlNone
    End With
    Selection.Interior.ColorIndex = xlNone
    ActiveChart.SeriesCollection(1).Select
    With Selection.Border
        .Weight = xlThin
        .LineStyle = xlNone
    End With
    Selection.Shadow = False
    Selection.InvertIfNegative = False
    Selection.Interior.ColorIndex = xlNone
        ActiveChart.SeriesCollection(2).Select
    With Selection.Interior
        .ColorIndex = 32
    End With
    ActiveChart.SeriesCollection(3).Select
    With Selection.Interior
        .ColorIndex = 34
    End With
    ActiveChart.Axes(xlCategory).Select
    With Selection
        .CrossesAt = 1
        .TickLabelSpacing = 1
        .TickMarkSpacing = 1
        .AxisBetweenCategories = True
        .ReversePlotOrder = True
    End With
    Selection.TickLabels.AutoScaleFont = True
    With Selection.TickLabels.Font
        .Name = "Arial"
        .FontStyle = "Regular"
        .Size = 8
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    ActiveChart.Axes(xlValue).Select
    With Selection
        .MinimumScale = data.Cells(2, 2).value
        .MaximumScale = data.Cells(data.Rows.Count, 2) + data.Cells(data.Rows.Count, 3) + _
                                                         data.Cells(data.Rows.Count, 4)
        .MinorUnitIsAuto = True
        .MajorUnitIsAuto = True
        .Crosses = xlMaximum
        .ReversePlotOrder = False
        .ScaleType = xlLinear
        .DisplayUnit = xlNone
    End With
    Selection.TickLabels.AutoScaleFont = True
    With Selection.TickLabels.Font
        .Name = "Arial"
        .FontStyle = "Bold"
        .Size = 8
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    With Selection.TickLabels
        .ReadingOrder = xlContext
        .Orientation = 45
    End With
    ActiveChart.Legend.Select
    Selection.Position = xlBottom
    ActiveChart.Legend.LegendEntries(1).Select
    Selection.Delete
End Sub

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.