Dynamic variable cells in Solver VBA macro

hasselberg

New Member
Joined
Jun 8, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a macro that runs Solver in Excel, it currently uses two different ranges as the variable cells. See the code below.

VBA Code:
    SolverOk SetCell:="$D$27", MaxMinVal:=2, ValueOf:=0, ByChange:= _
        "$C$17:$C$23,$C$7:$I$11", Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverOptions MaxTime:=30, Iterations:=0, Precision:=0.9, Convergence:= _
        0.9, StepThru:=False, Scaling:=False, AssumeNonNeg:=True, Derivatives:=1
    SolverOptions PopulationSize:=200, RandomSeed:=0, MutationRate:=0.999, Multistart _:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
        IntTolerance:=0#, SolveWithout:=False, MaxTimeNoImp:=30
        
    SolverSolve userFinish:=True, ShowRef:=0
    SolverFinish KeepFinal:=1

Instead of having an absolute reference to $C$7:$I$11, I would want to only select the rows of the range where K7:K11="Unlocked" (note that this is a separate column). Is it possible to achieve in a simple way? I have attempted creating a named range in Excel, but I have so far been unsuccessful. Maybe it's easier to solve within the macro, however my VBA skills are nonexistant.

Thankful for any help!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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