LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default solver setcell= to an argument name rather than a cell in the worksheet

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
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
Which argument can be replaced by a Tag rather than a cell range? dwest4624 Excel Discussion (Misc queries) 0 July 21st 09 08:54 PM
Average: 2nd argument as a variable in another cell av(c6:c(a3)) Tony the Tiger Excel Discussion (Misc queries) 2 May 5th 08 12:39 AM
TIMEVALUE - can I use cell reference as argument? Steve Vincent Excel Worksheet Functions 3 May 5th 07 05:49 PM
using the name of the worksheet as argument radulucian Excel Worksheet Functions 2 December 6th 05 04:50 PM
Worksheet Name as argument in Custom Function Larry D Excel Programming 1 September 25th 03 08:31 PM


All times are GMT +1. The time now is 08:16 AM.

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"