View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Automate a Solver solution

On 5/23/2010 12:42 PM, Janet wrote:
Thanks!!! That did the trick, but now I don't know how to integrate the
macro I just wrote into the program that Howard gave me so it will repeat
itself for the relevant rows:

Sub ForHunRow()
Dim i As Integer
Dim j As Range, c As Range

i = Range("F1").Value
Set j = Range("D1:D400")

For Each c In j
c.Value = i
Next

End Sub


Hi. Here is a general outline.
Here, I have a function in D1, and the changing cells are in A1:C1.
The loop goes from Row 1 to 10. Hopefully, you can adjust it to your
situation. Not quite what I use, but it should give you some ideas.
In a loop, I find it best to just Reset everything.


Sub Demo()
'//Dana DeLouis
Dim R As Long
Dim Target
Dim ChgCells

SolverOptions AssumeLinear:=True
SolverOptions AssumeNonNeg:=True

For R = 1 To 10 'Row 1 to 10
SolverReset
Target = Cells(R, 4).Address
ChgCells = Cells(R, 1).Resize(1, 3).Address

SolverOk SetCell:=Target, MaxMinVal:=2, ByChange:=ChgCells
SolverAdd CellRef:=ChgCells, Relation:=3, FormulaText:="1"
SolverAdd CellRef:=ChgCells, Relation:=1, FormulaText:="10"
SolverSolve True
Next R
End Sub

= = = = = = =
HTH :)
Dana DeLouis