ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trendline Data (https://www.excelbanter.com/excel-programming/307494-re-trendline-data.html)

Chip Pearson

Trendline Data
 
If you mean to get the polynomial coefficients, try something
like the following:

Dim TL As Trendline
Dim A As Double, B As Double, C As Double, D As Double, E As
Double, F As Double, G As Double
Dim S As String
Dim Arr As Variant
Dim Pos As Integer
Set Ser = Chart1.SeriesCollection(1)
Set TL = Ser.Trendlines.Add(xlPolynomial, 6) ' change 6 to
appropriate order
TL.DisplayEquation = True



TL.DataLabel.NumberFormat = "0.000000000000000"
S = TL.DataLabel.Text
Pos = InStr(1, S, "=")
S = Mid(S, Pos + 1)
S = Replace(S, " + ", "|+")
S = Replace(S, " - ", "|-")
Arr = Split(S, "|")

A = 0: B = 0: C = 0: D = 0: E = 0: F = 0: G
= 0
' g
Pos = InStr(1, Arr(LBound(Arr) + 0), "x")
G = CDbl(Left(Arr(LBound(Arr) + 0), Pos - 1))

' f
Pos = InStr(1, Arr(LBound(Arr) + 1), "x")
F = CDbl(Left(Arr(LBound(Arr) + 1), Pos - 1))

' e
Pos = InStr(1, Arr(LBound(Arr) + 2), "x")
E = CDbl(Left(Arr(LBound(Arr) + 2), Pos - 1))

' D
Pos = InStr(1, Arr(LBound(Arr) + 3), "x")
D = CDbl(Left(Arr(LBound(Arr) + 3), Pos - 1))

' c
Pos = InStr(1, Arr(LBound(Arr) + 4), "x")
C = CDbl(Left(Arr(LBound(Arr) + 4), Pos - 1))

' b
Pos = InStr(1, Arr(LBound(Arr) + 5), "x")
B = CDbl(Left(Arr(LBound(Arr) + 5), Pos - 1))

' a
A = CDbl(Arr(UBound(Arr)))



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"MF_gyps" wrote in message
...
I am looking for an Excel function or Excel VB Macro function

that will allow
me access to the actual data for a chart polynomial trendline.
Does this functionality exist?




Tom Ogilvy

Trendline Data
 
Note that your success will depend a lot on how many digits of precision you
use before you parse the equation coefficients.

--
Regards,
Tom Ogilvy


"MF_gyps" wrote in message
...
String manipulation of the equation box to get the coefficients is

something
I hadn't really considered but that definitely would work.
Back generating the trendline data from the coefficients should be easy.

I guess it is just suprising that there isn't a function to calculate

these
data points in cells for a polynomial fit the same way you can using the
packaged linear functions such as TREND.

Thank you very much Chip!






All times are GMT +1. The time now is 10:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com