Add a User-selected range to Solver Macro

samanthalane

New Member
Joined
Jul 10, 2009
Messages
1
Ok I admit I may be a little over my head trying this but I want to score some brownie points in my internship.

I used the macro recorder to record a macro for using solver as shown below:

Sub BreakEven()
'
' BreakEven Macro
'


SolverOk SetCell:="$G$32", MaxMinVal:=3, ValueOf:="250000", ByChange:= _
"$D$2:$D$31"
SolverSolve
End Sub

Everything will stay the same except that the ValueOf:="250000" I want to be user selected by choosing the cell on another worksheet.

Another thought I had is that the cell containing the "250000" will always be the same cell referenced so I'm guessing I can somehow easily define a variable to plug into the code above so that it would be something like: ValueOf:="cost" and then somewhere I define cost referencing that "250000" cell (which is on another page)

Help please. I'm sure these are silly basic questions.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello Samantha and welcome to MrExcel.

Try something like this

Rich (BB code):
Sub BreakEven()
'
' BreakEven Macro
'


SolverOk SetCell:="$G$32", MaxMinVal:=3, ValueOf:=Sheets("Sheet1").Range("G4").Value, ByChange:= _
"$D$2:$D$31"
SolverSolve
End Sub

Change the sheet name and cell to suit.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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