View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Syntax in worksheet functions for individual values instead of ranges

"REM" wrote:
I am trying to use the TREND function in a macro but cannot
work out the syntax.

[....]
ActiveCell.FormulaR1C1 = "=TREND({5;10},{10;20},15)"


Works fine for me in XL2003 with VBA 6.5.

That is, when an cell is indeed selected. I wonder if you selected another
object (e.g. a chart) at the time you executed that line in the macro.

REM wrote:
dont know how to evaluate this to a variable,
without using a cell.


y = Evaluate("=TREND({5;10},{10;20},15)")

or [1]:

y = WorksheetFunction.Forecast(15, Array(5,10), Array(10,20))


REM wrote:
Ideally I would like the numbers to be variables also.


knownY = Array(5,10)
knownX = Array(10,20)
x = 15
y = WorksheetFunction.Forecast(x,knownY,knownX)

-----
[1] I don't know why one of the following does not work. I don't care
because I would use FORECAST for this purpose instead of TREND anyway.

y = WorksheetFunction.Trend(Array(5,10), Array(10,20), 15)
y = WorksheetFunction.Trend(Array(5,10), Array(10,20), Array15))