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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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,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