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

In quite a few of my excel projects I use trendlines to predict values.
Currently I manually input the trendline formula into my calculations. But
every time the trendline gets updaten (by adding more data to my database) I
have to manually change the formula in my cells. Currently I'm trying to
automate that.

Since there didn't seem to be a direct/straightforward way of doing this,
I've recorded a macro that extracts the formula and pastes it in a cell. This
works without problems. The formula appears as follows:

y = 136,56x-0,0929 (with -0,0929 being the power of x)

next I wabt to replace x with a cell, so "x" is automatically replaced by
"*E72^", this also works without problems, now the value of my target cell
looks like this:

y = 136,56*E72^-0,0929

finally, I want to replace "y = " with "=". As soon as I do this, I get a
Error 1004 (typed formula contains an error).

If I manually replace "y = " with "=", the calculations go without problems
but I just can't seem to be able to get it to work automatically.

Could anyone help me out?

this is my code sofar:

__________________________________________________ _________
Sub UitlezenTrendlijnformule()

Dim Formule As String

ActiveSheet.ChartObjects("Grafiek 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Trendlines(1).Data Label.Select
Formule = CStr(Selection.Caption)
ActiveWindow.Visible = False
Windows("filename.xls").Activate
Range("F72").Select
ActiveCell.Value = Formule

Range("F72").Select
ActiveCell.Replace What:="x", Replacement:="*E72^", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="x", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
..Activate

Range("F72").Select
ActiveCell.Replace What:="y = ", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="y = ", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

End Sub
__________________________________________________ ______

Again, I might be doing this the hard way, so if there is an easier way I'd
like to know :)

PS, I hope everything is clear since English isn't my native language (and
that explains the , and . mixups as well ;) )
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using Trendline Formula

If you have replace all cells containing "y ="

then this line will cause an error:

Cells.Find(What:="y = ", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

the other problem could be the fact that you are using comma as your
delimiter. Often, when VBA is involved, you have to use US formatting. Try
replacing the "," with "." before you replace the "y = "

--
Regards,
Tom Ogilvy


"Maarten" wrote in message
...
In quite a few of my excel projects I use trendlines to predict values.
Currently I manually input the trendline formula into my calculations. But
every time the trendline gets updaten (by adding more data to my database)

I
have to manually change the formula in my cells. Currently I'm trying to
automate that.

Since there didn't seem to be a direct/straightforward way of doing this,
I've recorded a macro that extracts the formula and pastes it in a cell.

This
works without problems. The formula appears as follows:

y = 136,56x-0,0929 (with -0,0929 being the power of x)

next I wabt to replace x with a cell, so "x" is automatically replaced by
"*E72^", this also works without problems, now the value of my target cell
looks like this:

y = 136,56*E72^-0,0929

finally, I want to replace "y = " with "=". As soon as I do this, I get a
Error 1004 (typed formula contains an error).

If I manually replace "y = " with "=", the calculations go without

problems
but I just can't seem to be able to get it to work automatically.

Could anyone help me out?

this is my code sofar:

__________________________________________________ _________
Sub UitlezenTrendlijnformule()

Dim Formule As String

ActiveSheet.ChartObjects("Grafiek 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Trendlines(1).Data Label.Select
Formule = CStr(Selection.Caption)
ActiveWindow.Visible = False
Windows("filename.xls").Activate
Range("F72").Select
ActiveCell.Value = Formule

Range("F72").Select
ActiveCell.Replace What:="x", Replacement:="*E72^", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="x", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)

_
.Activate

Range("F72").Select
ActiveCell.Replace What:="y = ", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="y = ", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

End Sub
__________________________________________________ ______

Again, I might be doing this the hard way, so if there is an easier way

I'd
like to know :)

PS, I hope everything is clear since English isn't my native language (and
that explains the , and . mixups as well ;) )



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Using Trendline Formula

Maarten -

If you would prefer a worksheet approach instead of VBA, you could use a
combination of the EXP, LN, SLOPE, and INTERCEPT worksheet functions to get
the parameters of the trendline.

For example, for the power function y=c*x^b,
c = EXP(INTERCEPT(LN(Yrange),LN(Xrange)))
b = SLOPE(LN(Yrange),LN(Xrange))

- Mike

www.mikemiddleton.com

++++++++++++++++++++

"Maarten" wrote in message
...
In quite a few of my excel projects I use trendlines to predict values.
Currently I manually input the trendline formula into my calculations. But
every time the trendline gets updaten (by adding more data to my database)
I
have to manually change the formula in my cells. Currently I'm trying to
automate that.

Since there didn't seem to be a direct/straightforward way of doing this,
I've recorded a macro that extracts the formula and pastes it in a cell.
This
works without problems. The formula appears as follows:

y = 136,56x-0,0929 (with -0,0929 being the power of x)

next I wabt to replace x with a cell, so "x" is automatically replaced by
"*E72^", this also works without problems, now the value of my target cell
looks like this:

y = 136,56*E72^-0,0929

finally, I want to replace "y = " with "=". As soon as I do this, I get a
Error 1004 (typed formula contains an error).

If I manually replace "y = " with "=", the calculations go without
problems
but I just can't seem to be able to get it to work automatically.

Could anyone help me out?

this is my code sofar:

__________________________________________________ _________
Sub UitlezenTrendlijnformule()

Dim Formule As String

ActiveSheet.ChartObjects("Grafiek 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Trendlines(1).Data Label.Select
Formule = CStr(Selection.Caption)
ActiveWindow.Visible = False
Windows("filename.xls").Activate
Range("F72").Select
ActiveCell.Value = Formule

Range("F72").Select
ActiveCell.Replace What:="x", Replacement:="*E72^", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="x", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
_
.Activate

Range("F72").Select
ActiveCell.Replace What:="y = ", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Cells.Find(What:="y = ", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

End Sub
__________________________________________________ ______

Again, I might be doing this the hard way, so if there is an easier way
I'd
like to know :)

PS, I hope everything is clear since English isn't my native language (and
that explains the , and . mixups as well ;) )



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
Trendline formula juanpablo Excel Discussion (Misc queries) 6 October 18th 09 08:56 AM
Formula in Trendline juanpablo Excel Discussion (Misc queries) 0 October 16th 09 08:20 PM
how do i extract the formula from a trendline in Excel? DeanP Charts and Charting in Excel 1 May 5th 09 07:19 PM
Can I generate a mX+c Trendline Formula without a graph mcampbe5 Excel Worksheet Functions 2 October 24th 07 04:14 PM
Trendline Formula Problems John1791 Charts and Charting in Excel 2 June 19th 07 06:11 PM


All times are GMT +1. The time now is 02:49 PM.

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"