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

the_arcadian

New Member
Joined
Jun 20, 2019
Messages
7
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!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top