RobBroekhuis
Technical User
This is driving me crazy. Trying to use Excel's solver, using the following code:
SHconv and Gfinal are single-cell named ranges on sheet1. The proper reference to solver.xla has been set. The code executes, but refuses to put in the first constraint (i.e., the first SolverAdd statement doesn't do anything). This is obvious from the solverget values, which return 0 on first call, and 1 on second call. The same happens when I record the macro - Excel puts in extra junk and doesn't name the ranges in the code, but it amounts to a similar macro. It does what it needs to do when I record the macro, but doesn't work when I try to replay it. (The constraint is essential, otherwise Excel gets into numerical problems). Anyone know how to get around this?
Thanks
Rob
![[flowerface] [flowerface] [flowerface]](/data/assets/smilies/flowerface.gif)
Code:
Sub findshiftconversion()
SolverReset
SolverOk SetCell:="Gfinal", MaxMinVal:=2, ByChange:="SHconv"
SolverAdd CellRef:="SHconv", Relation:=1, FormulaText:=1
MsgBox (solverget(5, "sheet1"))
SolverAdd CellRef:="SHconv", Relation:=3, FormulaText:=0
MsgBox (solverget(5, "sheet1"))
SolverSolve
End Sub
Thanks
Rob
![[flowerface] [flowerface] [flowerface]](/data/assets/smilies/flowerface.gif)