Private Sub Worksheet_Activate()
Worksheet_Change [C5] 'lance la macro
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dat As Range, dest As Range, graph As Chart, i&, P As Range, col As Variant, a(), j%, n&, c As Range
Set dat = [C5]
If Intersect(Target, dat) Is Nothing Then Exit Sub
Set dest = [B7] '1ère cellule de destination, à adapter
Set graph = ChartObjects(1).Chart
Application.ScreenUpdating = False
'---RAZ---
dest.Resize(Rows.Count - dest.Row + 1, 2).ClearContents
For i = graph.SeriesCollection.Count To 1 Step -1
graph.SeriesCollection(i).Delete
Next
If Not IsDate(dat) Then Exit Sub
'---filtrage du tableau source et création des séries---
With Sheets("Notes") 'adapter éventuellement
Set P = Intersect(.Rows("15:" & .Rows.Count), .UsedRange.EntireRow)
End With
If P Is Nothing Then Exit Sub
col = Application.Match(dat, P.Rows(1), 0)
If IsError(col) Then Exit Sub
For Each c In P.Rows(1).Resize(, col).SpecialCells(xlCellTypeConstants, 1)
ReDim Preserve a(j)
a(j) = c.Text
j = j + 1
Next
ThisWorkbook.Names.Add "X", a 'nom défini sur une matrice
For i = 5 To P.Rows.Count
If P(i, col) > 1.5 Then 'critère à adapter
n = n + 1
dest(n) = P(i, 1)
dest(n, 2) = P(i, col)
j = 0: Erase a
For Each c In P.Rows(i).Resize(, col).SpecialCells(xlCellTypeConstants, 1)
ReDim Preserve a(j)
a(j) = c
j = j + 1
Next c
ThisWorkbook.Names.Add "Y_" & n, a 'nom défini sur une matrice
graph.SeriesCollection.NewSeries
graph.SeriesCollection(n).Name = dest(n)
graph.SeriesCollection(n).XValues = "'" & ThisWorkbook.Name & "'!X"
graph.SeriesCollection(n).Values = "'" & ThisWorkbook.Name & "'!Y_" & n
End If
Next
End Sub