SOLVER: How to call a VBA subprocedure after each solver iteration?

the_arcadian

New Member
Joined
Jun 20, 2019
Messages
5
Hi Mr. Excel,

I've scoured the internet and can't find the answer to this question. Everyone seems to get stuck in the same place (case #1, case #2, case #3, case #4).

The guidance for the SolverSolve function indicates that you can use ShowRef to pass a macro/sub into Solver after each of Solver's iterations. However, try as I might, I can't seem to get Solver to call the macro.

Code:
Sub SolverMacro()

Application.Calculation = xlAutomatic

Dim ChngCell_Cell As String
Dim SolverTarget As String

ChngCell_Cell = Range("ChangeCell_Cell").Value
SolverTarget = Range("Solver.Target").Value

SolverReset
SolverOptions StepThru:=True

SolverOk SetCell:=SolverTarget, MaxMinVal:=3, ValueOf:=0, ByChange:=ChngCell_Cell
SolverSolve UserFinish:=True, ShowRef:="MacroPass"

End Sub
Code:
Sub MacroPass(Reason As Integer)

Debug.Print "made it!"
MacroPass = 0

End Sub
I have searched every forum I could find for this, and I can't find anything. Would be blown away if someone can help here!
 

Forum statistics

Threads
1,085,490
Messages
5,383,963
Members
401,868
Latest member
herbalgirlskincare

Some videos you may like

This Week's Hot Topics

Top