A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Does the Solver, when run through a VBA induced loop only work once?
No. But you should call SoverReset before you calculate the formula to make sure all settings are correct.
Execute the sub below in an empty sheet.
Andreas.
Sub Example_SolverPrecision()
Dim i As Integer
Dim A As Range, B As Range, C As Range
Cells.ClearContents
Set A = Range("A1")
Set B = Range("B1")
Set C = Range("C1")
For i = 1 To 16
'Setup the Pythagoras formula
C.Formula = "=Sqrt(" & A.Address & "^2+" & B.Address & "^2)"
SolverReset
'Solve first row with 0.1, second row with 0.01, etc.
SolverOptions Precision:=1 / 10 ^ i
'Solve cell in column C, change cells in column A and B
SolverOk SetCell:=C.Address, MaxMinVal:=3, ValueOf:=5, ByChange:=A.Address & "," & B.Address
'Cell in column B must be an integer
SolverAdd CellRef:=B.Address, Relation:=4
'Solve it
SolverSolve True
'next row
Set A = A.Offset(1)
Set B = B.Offset(1)
Set C = C.Offset(1)
Next
End Sub