SOLVER VBA making range dynamic

vbanovice1992

New Member
Joined
Jun 18, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys I am using solver to identify from multiply amounts which add up to a specific number. I would like to make the "By change " to a dynamic range that will work no matter how many values are entered . I've been trying this for now 3 weeks and would appreciate someone helping me with the code here is the code I have".


SolverOk SetCell:="$F$6", MaxMinVal:=3, ValueOf:=0, ByChange:="$B$5:$B$16", _
Engine:=2, EngineDesc:="Simplex LP"
SolverOk SetCell:="$F$6", MaxMinVal:=3, ValueOf:=0, ByChange:="$B$5:$B$16", _
Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
 

Attachments

  • solver.PNG
    solver.PNG
    91.9 KB · Views: 28

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try setting a range to use:

VBA Code:
Sub test()

Dim sht As Worksheet
Dim myrange As Range
Dim LastRow As Long

Set sht = ActiveSheet

LastRow = sht.Cells(sht.Rows.Count, "C").End(xlUp).Row

Set myrange = Range("B5:$B" & LastRow)


SolverOk SetCell:="$F$6", MaxMinVal:=3, ValueOf:=0, ByChange:=myrange, _
Engine:=2, EngineDesc:="Simplex LP"

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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