View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mike hutchins mike hutchins is offline
external usenet poster
 
Posts: 1
Default Excluding cells in custom TREND function

I'm trying to create a user defined function for a polynominal
regression that allows specified data to be excluded from the
calculation.
The following code works fine where there's only one "daynum" X-array
(i.e.
the trend is a straight-line). How should it be modified to cope
with two X-arrays (i.e. X and X^2) to produce a curvefit?
TIA....

Function XTREND(Array_daynum, Array_devs, ArrayIgnore)
Dim new_array_daynum(), new_array_devs()

arrayx = Range("Array_daynum").Value
arrayy = Range("Array_devs").Value
arrayc = Range("ArrayIgnore").Value

For L = 1 To UBound(arrayx)
c = arrayc(L, 1)
If c = 0 Then
x = arrayx(L, 1)
y = arrayy(L, 1)
j = j + 1
ReDim Preserve new_array_daynum(1 To j)
new_array_daynum(j) = x
ReDim Preserve new_array_devs(1 To j)
new_array_devs(j) = y
End If
Next L

With Application.WorksheetFunction
XTREND = .Trend(new_array_devs, new_array_daynum, Array_daynum)
End With
End Function