Using named ranges in Solver VBA

wgjack75

New Member
Joined
Oct 29, 2019
Messages
1
Hi,

I want to run Solver from VBA, and I would like to vary the "ByChange" cells depending on certain conditions in other cells. (This is to minimise the number of ByChange cells, and remove any redundant cells i.e. ones that definitely will have no effect on the target cell). This means that the range of ByChange cells will be non-contiguous. I have got the code to work okay to define this non-contiguous range (using the If and Union functions). However, I cannot get the Solver VBA code to accept the resulting defined range. It may be that this is just beyond the capabilities of Solver, but I thought I would ask in case anybody knows a way around this.

The relevant code (for Solver) is simply as below. SolverRange is the range that I have defined earlier in the subroutine using the If and Union functions. For example, SolverRange might equal the range (A4:A7,A10:A14,G8:G12)

SolverOk SetCell:="JanNetCost", MaxMinVal:=2, ValueOf:=0, ByChange:=Range("SolverRange"), Engine:=3, EngineDesc:="Evolutionary"

I have also tried it without the Range function, i.e. ByChange:=SolverRange, but that doesn't work either.

Any help gratefully appreciated!

Thank you,

Jack.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,713
Messages
6,174,041
Members
452,542
Latest member
Bricklin

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