Sub CrééGraph()
Dim DLig As Long, Lig As Long
Dim FirstCel As String, LastCel As String
Dim FirstF As String, LastF As String
Dim FirstP As String, LastP As String
Dim VAn As Integer
Dim Zone As String
VAn = Sheets("Feuil1").TextBox1
FirstCel = "": LastCel = ""
An_ok = False
VAn = Sheets("Feuil1").TextBox1
For n = 1 To Sheets("Donnée").Range("A65536").End(xlUp).Row
If Year(Sheets("Donnée").Range("A" & n)) = VAn Then
An_ok = True
Exit For
End If
Next n
If An_ok = False Then
MsgBox ("Cette Année n'existe pas")
Exit Sub
End If
FirstCel = "": LastCel = ""
With Sheets("Donnée")
DLig = .Range("A" & Rows.Count).End(xlUp).Row
' Trouver la zone de données sources pour le graphique
For Lig = 1 To DLig + 1
If Year(.Range("A" & Lig)) = VAn And FirstCel = "" Then
FirstCel = .Range("A" & Lig).Address(0, 0)
End If
If FirstCel <> "" And Year(.Range("A" & Lig)) <> VAn Then
LastCel = .Range("A" & Lig - 1).Address(0, 0)
Exit For
End If
Next
FirstF = "F" & Mid(FirstCel, 2)
LastF = "F" & Mid(LastCel, 2)
FirstP = "P" & Mid(FirstCel, 2)
LastP = "P" & Mid(LastCel, 2)
Zone = FirstCel & ":" & LastCel & "," & FirstF & ":" & LastF & "," & FirstP & ":" & LastP
Sheets("graph.1").Activate
Sheets("graph.1").Shapes(1).Select
ActiveChart.SetSourceData Source:= _
Sheets("Donnée").Range(Zone), PlotBy:=xlColumns
Range("A1").Select
End With
End Sub