Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Running a Macro at every Solver Iteration


I am trying to run a macro at every solver iteration through showref.
However, the solver goes through only the first iteration and does not
optimize the target cell updated by the macro called through showref.

I found an old thread from a couple of years ago on the same issue.
Just wondering if folks were able to resolve this.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Running a Macro at every Solver Iteration

Hi. It works fine in Excel 2003.
However, the documentation is a bit flakey.
If you post your code, we may be able to help.

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"sk" wrote in message
ups.com...

I am trying to run a macro at every solver iteration through showref.
However, the solver goes through only the first iteration and does not
optimize the target cell updated by the macro called through showref.

I found an old thread from a couple of years ago on the same issue.
Just wondering if folks were able to resolve this.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Running a Macro at every Solver Iteration

Here is the macro that I wrote to test the solver. As I mentioned, I
can get to the macro from the solver in the first iteration but not
back for further iterations. Do I need to force a return?

Thanks
Sharad

Sub Macro1()
'

SolverOk SetCell:="$B$5", MaxMinVal:=1, ValueOf:="0",
ByChange:="$B$2"
SolverAdd CellRef:="$B$1", Relation:=3, FormulaText:="25"
SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001,
AssumeLinear _
:=False, StepThru:=True, Estimates:=1, Derivatives:=1,
SearchOption:=1, _
IntTolerance:=5, Scaling:=False, Convergence:=0.0001,
AssumeNonNeg:=False

ans = SolverSolve(False, "Example()")

End Sub

Function Example()
Sheets("sheet1").Cells(1, "B") = -10 * Sheets("sheet1").Cells(2, "B") +
1000
End Function
-------------------
On Jan 25, 12:55 pm, "Dana DeLouis" wrote:
Hi. It works fine in Excel 2003.
However, the documentation is a bit flakey.
If you post your code, we may be able to help.

--
HTH :)
Dana DeLouis
Windows XP & Office 2003

"sk" wrote in oglegroups.com...





I am trying to run a macro at every solver iteration through showref.
However, the solver goes through only the first iteration and does not
optimize the target cell updated by the macro called through showref.


I found an old thread from a couple of years ago on the same issue.
Just wondering if folks were able to resolve this.


Thanks- Hide quoted text -- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Running a Macro at every Solver Iteration

Hi. In general, here is how you do it.
I've included some personal techniques.

SolverOk SetCell:="B5", MaxMinVal:=1, ByChange:="B2"
SolverOptions StepThru:=True
ans = SolverSolve(True, "Example")

- - -
You can drop =0 in a Max problem as it's ignored anyway.
I like to set StepThru on a separate line for these problems.
Note the correct call format
- - -

Here's one way for your Example function to work.

Function Example(WhyCalled As Integer)
'// WhyCalled is 1,2, or 3
'// Not necessary here...

With Sheets("Sheet1")
.Cells(1, 2) = -10 * .Cells(2, 2) + 1000
End With
Example = False ' <- Excel 2003
End Function

Good luck...
--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"sk" wrote in message
ups.com...
Here is the macro that I wrote to test the solver. As I mentioned, I
can get to the macro from the solver in the first iteration but not
back for further iterations. Do I need to force a return?

Thanks
Sharad

Sub Macro1()
'

SolverOk SetCell:="$B$5", MaxMinVal:=1, ValueOf:="0",
ByChange:="$B$2"
SolverAdd CellRef:="$B$1", Relation:=3, FormulaText:="25"
SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001,
AssumeLinear _
:=False, StepThru:=True, Estimates:=1, Derivatives:=1,
SearchOption:=1, _
IntTolerance:=5, Scaling:=False, Convergence:=0.0001,
AssumeNonNeg:=False

ans = SolverSolve(False, "Example()")

End Sub

Function Example()
Sheets("sheet1").Cells(1, "B") = -10 * Sheets("sheet1").Cells(2, "B") +
1000
End Function
-------------------
On Jan 25, 12:55 pm, "Dana DeLouis" wrote:
Hi. It works fine in Excel 2003.
However, the documentation is a bit flakey.
If you post your code, we may be able to help.

--
HTH :)
Dana DeLouis
Windows XP & Office 2003

"sk" wrote in
oglegroups.com...





I am trying to run a macro at every solver iteration through showref.
However, the solver goes through only the first iteration and does not
optimize the target cell updated by the macro called through showref.


I found an old thread from a couple of years ago on the same issue.
Just wondering if folks were able to resolve this.


Thanks- Hide quoted text -- Show quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Running a Macro at every Solver Iteration

Thanks, this is great
----------

On Jan 25, 3:08 pm, "Dana DeLouis" wrote:
Hi. In general, here is how you do it.
I've included some personal techniques.

SolverOk SetCell:="B5", MaxMinVal:=1, ByChange:="B2"
SolverOptions StepThru:=True
ans = SolverSolve(True, "Example")

- - -
You can drop =0 in a Max problem as it's ignored anyway.
I like to set StepThru on a separate line for these problems.
Note the correct call format
- - -

Here's one way for your Example function to work.

Function Example(WhyCalled As Integer)
'// WhyCalled is 1,2, or 3
'// Not necessary here...

With Sheets("Sheet1")
.Cells(1, 2) = -10 * .Cells(2, 2) + 1000
End With
Example = False ' <- Excel 2003
End Function

Good luck...
--
HTH :)
Dana DeLouis
Windows XP & Office 2003

"sk" wrote in oglegroups.com...



Here is the macro that I wrote to test the solver. As I mentioned, I
can get to the macro from the solver in the first iteration but not
back for further iterations. Do I need to force a return?


Thanks
Sharad


Sub Macro1()
'


SolverOk SetCell:="$B$5", MaxMinVal:=1, ValueOf:="0",
ByChange:="$B$2"
SolverAdd CellRef:="$B$1", Relation:=3, FormulaText:="25"
SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001,
AssumeLinear _
:=False, StepThru:=True, Estimates:=1, Derivatives:=1,
SearchOption:=1, _
IntTolerance:=5, Scaling:=False, Convergence:=0.0001,
AssumeNonNeg:=False


ans = SolverSolve(False, "Example()")


End Sub


Function Example()
Sheets("sheet1").Cells(1, "B") = -10 * Sheets("sheet1").Cells(2, "B") +
1000
End Function
-------------------
On Jan 25, 12:55 pm, "Dana DeLouis" wrote:
Hi. It works fine in Excel 2003.
However, the documentation is a bit flakey.
If you post your code, we may be able to help.


--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"sk" wrote in
oglegroups.com...


I am trying to run a macro at every solver iteration through showref.
However, the solver goes through only the first iteration and does not
optimize the target cell updated by the macro called through showref.


I found an old thread from a couple of years ago on the same issue.
Just wondering if folks were able to resolve this.


Thanks- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -


Reply
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
Having Solver Call a macro for each iteration Andrew Harris Excel Discussion (Misc queries) 2 March 8th 10 04:27 AM
How do I use Excel Solver (for an Iteration in a row) for several no.of times? Deepak[_2_] Excel Discussion (Misc queries) 0 December 9th 08 06:35 AM
"unexpected error" when running solver from a macro floodgate Excel Programming 4 September 30th 04 01:36 AM
"unexpected error" when running solver from a macro floodgate[_2_] Excel Programming 0 September 29th 04 11:28 AM
Running Solver Add-In through VB ? Luqman Excel Programming 2 April 5th 04 06:54 PM


All times are GMT +1. The time now is 01:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"