1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Option Explicit
Function CoefTend(ByVal Sr As Series)
With Sr
If .Trendlines.Count > 0 Then .Trendlines(1).Delete
With .Trendlines.Add
.Type = xlPolynomial
.Order = 6
.DisplayEquation = True
.DataLabel.NumberFormat = "0.00000E+00"
Application.Wait Time + TimeSerial(0, 0, 1)
CoefTend = ExtrCoef(.DataLabel.Text)
.Delete
End With
End With
End Function
Private Function ExtrCoef(ByVal Tmp As String)
Dim i As Byte, n As Byte
Dim Tb
Tmp = Replace(Tmp, "y = ", "")
Tmp = Replace(Tmp, " + ", "|+")
Tmp = Replace(Tmp, " - ", "|-")
Tb = Split(Tmp, "|")
For i = LBound(Tb) To UBound(Tb)
n = InStr(Tb(i), "x")
If n Then Tb(i) = Left(Tb(i), n - 1)
Next i
ExtrCoef = Tb
End Function |