Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I would like to use solver in VBA and setcell= to an argument name
rather than a cell in the worksheet so I can keep the overhead in VBA. I am writing a least squares routine that will make a function for polynomial fits, similar to how trend or forcast work Here is my code, it does not work in VBA because I am mixing ranges with variables and such. ' Function created by Travis Beek Function Poly2(Known_Xs, Known_Ys, New_X, Optional Statistics) If Known_Xs.Rows.Count < Known_Ys.Rows.Count Then MsgBox "Known_Xs does not have the same number of rows as Known_Ys." & Chr(13) _ & "The answer in " & ActiveCell.Address & _ " will not be correct until they match.", vbExclamation, "Warning" End If For n = 1 To Known_Xs.Rows.Count X = Known_Xs.Item(n, 1) 'ref(r,c) is relative to the range, not the sheet y = Known_Ys.Item(n, 1) a = 1 'should the constants be outside the loop? b = 1 c = 1 Sumsqs = (y - (a * X ^ 2 + b * X + c)) ^ 2 + Sumsqs Next n SolverOK SetCell:=Sumsqs, MaxMinVal:=2, ByChange:="a,b,c" SolverSolve Poly2 = Sumsqs ' For Each blah In Known_Xs.Cells 'also works, loop repeats at the "Next" operator ' total = total + blah.Value ' Next End Function --- Message posted from http://www.ExcelForum.com/ |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Which argument can be replaced by a Tag rather than a cell range? | Excel Discussion (Misc queries) | |||
Average: 2nd argument as a variable in another cell av(c6:c(a3)) | Excel Discussion (Misc queries) | |||
TIMEVALUE - can I use cell reference as argument? | Excel Worksheet Functions | |||
using the name of the worksheet as argument | Excel Worksheet Functions | |||
Worksheet Name as argument in Custom Function | Excel Programming |