Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, [O7:O8]) Is Nothing Then Exit Sub
Dim crit1$, crit2$, tablo, n&, i&, j%, f$
crit1 = [O7] & "*": crit2 = [O8] & "*"
tablo = Sheets("bdd").[A1].CurrentRegion.Resize(, 6).FormulaR1C1 'matrice, plus rapide
n = 1
For i = 2 To UBound(tablo)
If tablo(i, 1) Like crit1 And tablo(i, 2) Like crit2 Then
n = n + 1
For j = 1 To 6
tablo(n, j) = tablo(i, j)
Next j
End If
Next i
With Sheets("Filtre")
Application.ScreenUpdating = False
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
.UsedRange.ClearContents 'RAZ
.[A1].Resize(n, 6).FormulaR1C1 = tablo
If n > 1 Then
.[C2].Resize(n - 1).Name = "Y" 'plage nommée
.[D2].Resize(n - 1).Name = "X" 'plage nommée
.[E2].Resize(n - 1).Name = "Yplus20" 'plage nommée
.[F2].Resize(n - 1).Name = "Ymoins20" 'plage nommée
.[G1] = "TC": .[H1] = "Y/TC": .[I1] = "Commentaire"
f = ChartObjects(1).Chart.SeriesCollection(2).Trendlines(1).DataLabel.Text
f = Replace(Mid(f, 5), ",", ".")
f = Replace(f, "e", "*EXP(")
f = "=" & Replace(f, "x", "*X") & ")"
.[G2].Resize(n - 1).FormulaArray = f 'formule matricielle
.[H2].Resize(n - 1) = "=RC[-5]/RC[-1]"
.[I2].Resize(n - 1) = "=IF(RC[-1]>1.2,""HAUT"",IF(RC[-1]<0.8,""BAS"",""""))"
End If
.Columns.AutoFit
End With
End Sub