Bonjour,
Une proposition à étudier et à adapter.
Cdlt.
Option Explicit
Public Sub Create_Chart()
Dim ws As Worksheet
Dim objChart As ChartObject
Dim n As Long, i As Long
Dim Cell As Range, rngX As Range, rngY As Range
Dim sTitle As String
Set ws = ActiveWorkbook.Worksheets("Graphique")
On Error Resume Next
ws.ChartObjects("MyG").Delete
On Error GoTo 0
With ws
sTitle = .Cells(1, 1).Value & " - " & .Cells(1, 2).Value
n = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 4 To n
If IsEmpty(.Cells(i, 2)) Or .Cells(i, 2) = 0 Then
.Cells(i, 18).Value = CVErr(xlErrNA)
Else
.Cells(i, 18).Value = .Cells(i, 2).Value
End If
Next i
Set rngX = .Cells(4, 1).Resize(n - 3)
Set rngY = .Cells(4, 18).Resize(n - 3)
Set Cell = .Cells(4, 4)
Set objChart = .ChartObjects.Add(Cell.Left, Cell.Top, 550, 275)
objChart.Name = "MyG"
With objChart.Chart
.ChartType = xlLine
.ChartStyle = 230
.HasTitle = True
.ChartTitle.Characters.Text = sTitle
.SeriesCollection.NewSeries
With .SeriesCollection(1)
.XValues = rngX
.Values = rngY
.Name = "Points AC/AD"
End With
With .FullSeriesCollection(1)
.ApplyDataLabels
.DataLabels.Position = xlLabelPositionBelow
End With
.Axes(xlCategory).TickLabels.NumberFormat = "dd"
.Axes(xlValue).Delete
End With
End With
End Sub