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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,925
Messages
6,175,421
Members
452,640
Latest member
steveridge

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