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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

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