LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ly Ly is offline
external usenet poster
 
Posts: 2
Default Excel Solver with VB

I am trying to solve a bunch of equations with similar structure (say,
min $M$i by change of $B$i:$E$i with subject to a few constraints, i
runs from 1 to 100). I found this topic
http://groups.google.com/group/micro...bece79402a0da4
very helpful. However, when I run my macro, all 100 results were
exactly the same and very different from what I would have gotten had I
manually gone through the Solver GUI.

My initial thought was that maybe the constraints were not cleared
after each time. But SolverReset should take care of this problem, I
suppose. I still have a few hundred more equations to run. So I would
very appreciate it if anyone could tell me how to fix the problem and
what I did wrong.

Here is my macro:

Sub EF()

For j = 0 To 3
SolverReset
Set firstrange = Range("M38").Offset(j, 0)
Set secondrange = Range("B38:E38").Offset(j, 0)
Set cons1 = Range("B38").Offset(j, 0)
Set cons2 = Range("C38").Offset(j, 0)
Set cons3 = Range("D38").Offset(j, 0)
Set cons4 = Range("E38").Offset(j, 0)
Set cons5 = Range("J38").Offset(j, 0)
Set cons6 = Range("L38").Offset(j, 0)
Set targetER = Range("A38").Offset(j, 0)

SolverOk _
SetCell:=firstrange, _
MaxMinVal:=2, _
ValueOf:=0, _
ByChange:=secondrange

SolverAdd _
CellRef:=cons1, _
Relation:=3, _
FormulaText:="0"

SolverAdd _
CellRef:=cons2, _
Relation:=3, _
FormulaText:="0"

SolverAdd _
CellRef:=cons3, _
Relation:=3, _
FormulaText:="0"

SolverAdd _
CellRef:=cons4, _
Relation:=3, _
FormulaText:="0"

SolverAdd _
CellRef:=cons5, _
Relation:=2, _
FormulaText:="1"

SolverAdd _
CellRef:=cons6, _
Relation:=3, _
FormulaText:=targetER


SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1

Next j

End Sub

Thank you very much.

 
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
How to replace Excel solver with some free solver codes in Excel V ct2147 Excel Programming 2 November 8th 06 07:06 PM
Interesting Solver problem (Solver encounters an error) MrShorty Excel Discussion (Misc queries) 3 December 22nd 05 10:52 PM
Excel: Solver leo Excel Worksheet Functions 1 April 29th 05 02:02 AM
Excel Solver Hari Prasadh[_2_] Excel Programming 3 March 31st 05 06:41 AM
Resetting Solver Manually to Fix Solver Bug Stratuser Excel Programming 0 September 13th 04 07:04 PM


All times are GMT +1. The time now is 01:47 PM.

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"