Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Trendline Coefficients

I have a function that reads the coefficients of a trendline by
searching the datalabel.text It is by no means sophisticated, but it
works well. It is designed only for second order polynomials and
returns the a, b, or c coefficient (y=ax^2+bx+c) based on the user
"reference". That is =coeff("a") returns the a coefficient.

My question is....since the function doesn't truly reference anything
but the code, it doesn't update when the underlying data changes.
When the data changes the trendline is updated, but nothing triggers
the function to "recalculate". Is there a way to reference the chart,
such that when it changes the value is recalculated?.....will this
even work like changing the value in a referenced cell??

Thanks,
John

Public Function coeff(var As String) As Double

sEqn = Charts(1).SeriesCollection(1).Trendlines(1).DataLa bel.Text

fst = InStr(1, sEqn, "x2")
snd = InStr(fst + 1, sEqn, "x")

If Mid(sEqn, fst + 3, 1) = "+" Then
bsign = True
Else
bsign = False
End If

If Mid(sEqn, snd + 2, 1) = "+" Then
csign = True
Else
csign = False
End If

If var = "a" Then
coeff = Mid(sEqn, 5, fst - 5)
ElseIf var = "b" Then

If bsign = True Then
coeff = Mid(sEqn, fst + 5, snd - (fst + 5))
Else
coeff = "-" & Mid(sEqn, fst + 5, snd - (fst + 5))
End If

ElseIf var = "c" Then

If csign = True Then
coeff = Mid(sEqn, snd + 4, Len(sEqn) - snd + 3)
Else
coeff = "-" & Mid(sEqn, snd + 4, Len(sEqn) - snd + 3)
End If

End If

End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Trendline Coefficients

You have to make the function "volatile" For more search XL VBA help
for that term.

You may also want to look at code first shared by David Braden and
subsequently modified by me. See
Trendline Coefficients and Regression Analysis
http://www.tushar-mehta.com/publish_...nalysis/16.htm

In article . com,
says...
I have a function that reads the coefficients of a trendline by
searching the datalabel.text It is by no means sophisticated, but it
works well. It is designed only for second order polynomials and
returns the a, b, or c coefficient (y=ax^2+bx+c) based on the user
"reference". That is =coeff("a") returns the a coefficient.

My question is....since the function doesn't truly reference anything
but the code, it doesn't update when the underlying data changes.
When the data changes the trendline is updated, but nothing triggers
the function to "recalculate". Is there a way to reference the chart,
such that when it changes the value is recalculated?.....will this
even work like changing the value in a referenced cell??

Thanks,
John

Public Function coeff(var As String) As Double

sEqn = Charts(1).SeriesCollection(1).Trendlines(1).DataLa bel.Text

fst = InStr(1, sEqn, "x2")
snd = InStr(fst + 1, sEqn, "x")

If Mid(sEqn, fst + 3, 1) = "+" Then
bsign = True
Else
bsign = False
End If

If Mid(sEqn, snd + 2, 1) = "+" Then
csign = True
Else
csign = False
End If

If var = "a" Then
coeff = Mid(sEqn, 5, fst - 5)
ElseIf var = "b" Then

If bsign = True Then
coeff = Mid(sEqn, fst + 5, snd - (fst + 5))
Else
coeff = "-" & Mid(sEqn, fst + 5, snd - (fst + 5))
End If

ElseIf var = "c" Then

If csign = True Then
coeff = Mid(sEqn, snd + 4, Len(sEqn) - snd + 3)
Else
coeff = "-" & Mid(sEqn, snd + 4, Len(sEqn) - snd + 3)
End If

End If

End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Trendline Coefficients

Thanks. I made the function "volatile" and now it works with the F9
key (Reclaculate), but still doesn't update on its own. I can
certainly do the regression from first principles using XL. But since
I want to see the data and trendline graphically anyway, I might as
well use the equation.

John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 762
Default Trendline Coefficients

John -

Some ideas: A well-behaved user defined function will recalculate when the
arguments change. Instead of "first principles," you could use LINEST for
the calculations and OFFSET to get the individual coefficients, with or
without VBA. If you really want a VBA function, it could refer to the
worksheet data as its arguments, and then it would recalculate when the data
changed.

- Mike
www.MikeMiddleton.com



wrote in message
ups.com...
Thanks. I made the function "volatile" and now it works with the F9
key (Reclaculate), but still doesn't update on its own. I can
certainly do the regression from first principles using XL. But since
I want to see the data and trendline graphically anyway, I might as
well use the equation.
John



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Trendline Coefficients [email protected] Excel Discussion (Misc queries) 4 June 14th 07 05:57 PM
Extracting Trendline Coefficients [email protected] Excel Programming 4 June 14th 07 05:57 PM
Trendline Coefficients Sprinks Excel Programming 3 January 4th 06 01:27 PM
Coefficients of trendline Phung Anh via OfficeKB.com Excel Programming 1 December 12th 05 04:34 AM
Trendline coefficients MrUniverseman Charts and Charting in Excel 3 May 18th 05 12:56 PM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"