Thread: Trend funtion
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Trend funtion

Hi,

Try this:

Sub GetTrendData()

Dim xRng As Range, yRng As Range
Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

Set yRng = Cells(2, "A")
Set xRng = Cells(3, "A")

For i = 4 To lastrow Step 2
yRng = Union(yRng, Cells(i, "a"))
xRng = Union(xRng, Cells(i + 1, "a"))
Next i

Range("c1") = Application.Trend(yRng, xRng)

End Sub

HTH

"vijaya" wrote:

Ok

I have data like this:

A B A B A B A B
1 10 2 20 3 30 4 ?

The trend formula is =trend (known y, [known x],new x)

Generally we select the known y values which are in continuous cells, and
then select known x values, after which for a new x value €“ y-values could be
estimated.

But is there any way that this could be done by selecting y and x €“ values
which are in non-contiguous cells( like values if present in alternative
cells)

Is there a way to program:
1.Collect all the values present in alternate cells starting from say A2 (
these are my y-values)
2. Next collect all the values present in alternate cells starting from say
A3 (these will be x values)
3. Now can I use the trend function for forecasting??

Is this a way possible..