VBA Loop for Solver

simonesk

New Member
Joined
Jun 6, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Dear All,

I am not an expert of VBA at all, therefore, I'll try to be as clear as I can.

I am trying to create a code to automatically run a Solver across several columns. I managed to create a basic code that does the job, but that means that I have to copy and paste the code for all the rows I need it, and they are about 500.
I was wondering if you could kindly help me to make a code that loops through all the columns at regular intervals.

Here is a sample of what I need (without loop):

VBA Code:
Sub provando()
Worksheets("M1").Activate

    SolverReset
    SolverOptions precision:=0.000001, Iterations:=10000
    SolverOK setCell:=Range("$E$415"), maxMinVal:=2, ByChange:=Range("$E$411", "$E$412")
    SolverAdd cellRef:=Range("$E$412"), Relation:=3, formulaText:="$E$413"
    SolverAdd cellRef:=Range("$E$412"), Relation:=1, formulaText:="$E$414"
    SolverSolve UserFinish:=True
    SolverFinish KeepFinal:=1
    
    SolverReset
    SolverOptions precision:=0.000001, Iterations:=10000
    SolverOK setCell:=Range("$G$415"), maxMinVal:=2, ByChange:=Range("$G$411", "$G$412")
    SolverAdd cellRef:=Range("$G$412"), Relation:=3, formulaText:="$G$413"
    SolverAdd cellRef:=Range("$G$412"), Relation:=1, formulaText:="$G$414"
    SolverSolve UserFinish:=True
    SolverFinish KeepFinal:=1
    
    SolverReset
    SolverOptions precision:=0.000001, Iterations:=10000
    SolverOK setCell:=Range("$I$415"), maxMinVal:=2, ByChange:=Range("$I$411", "$I$412")
    SolverAdd cellRef:=Range("$I$412"), Relation:=3, formulaText:="$I$413"
    SolverAdd cellRef:=Range("$I$412"), Relation:=1, formulaText:="$I$414"
    SolverSolve UserFinish:=True
    SolverFinish KeepFinal:=1
    
End Sub

Could you be so kind to adjust it to make it loop until no columns are found?

Kind regards,

Simone
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA Loop for Solver
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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